Must provide a predicate to argmin

This commit is contained in:
Dane Johnson 2024-11-11 15:38:13 -06:00
parent 56594fd146
commit 87384f611c
2 changed files with 3 additions and 3 deletions

4
d-.scm
View File

@ -48,9 +48,9 @@
(define (partial fn . args) (define (partial fn . args)
(lambda x (apply fn (append args x)))) (lambda x (apply fn (append args x))))
(define (argmin f . vals) (define (argmin arg lt? . vals)
(reduce (lambda (val min) (reduce (lambda (val min)
(if (< (f val) (f min)) (if (lt? (arg val) (arg min))
val val
min)) min))
#f #f

View File

@ -53,4 +53,4 @@
(define-test argmin (define-test argmin
(test (test
(assert (equal? (argmin cdr '(a . 5) '(b . 2) '(c . 3)) '(b . 2))))) (assert (equal? (argmin cdr < '(a . 5) '(b . 2) '(c . 3)) '(b . 2)))))