add some more functions

This commit is contained in:
Dane Johnson 2024-10-25 15:16:04 -05:00
parent 76b11b0cf5
commit f3d47afc5f
2 changed files with 14 additions and 2 deletions

12
d-.scm
View File

@ -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))

View File

@ -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)))))