From f3d47afc5fcdf968bfc41b71c75f5229ac8bc438 Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Fri, 25 Oct 2024 15:16:04 -0500 Subject: [PATCH] add some more functions --- d-.scm | 12 +++++++++++- test.scm | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/d-.scm b/d-.scm index 5939457..a1baea3 100644 --- a/d-.scm +++ b/d-.scm @@ -1,8 +1,10 @@ (define-module (d-) + #:use-module (srfi srfi-1) #:export (~> ~>> - partial)) + partial + argmin)) (define-syntax ~> (syntax-rules () @@ -18,3 +20,11 @@ (define (partial fn . args) (lambda x (apply fn (append args x)))) + +(define (argmin f . vals) + (reduce (lambda (val min) + (if (< (f val) (f min)) + val + min)) + #f + vals)) diff --git a/test.scm b/test.scm index ccd5dee..4f91c28 100644 --- a/test.scm +++ b/test.scm @@ -29,4 +29,6 @@ (assert (= (value 4) 1/2)) (assert (= (value 1) 2)))) - +(define-test argmin + (test + (assert (equal? (argmin cdr '(a . 5) '(b . 2) '(c . 3)) '(b . 2)))))