Add "upply" (U-shaped apply, names are hard)

This commit is contained in:
Dane Johnson 2024-11-22 09:27:07 -06:00
parent e6209fa8a4
commit e209bfe130
2 changed files with 10 additions and 0 deletions

5
d-.scm
View File

@ -12,6 +12,7 @@
partial
argmin
iterate
upply
generator
macro-expand))
@ -72,6 +73,10 @@
v
(iterate (1- n) f (f v))))
(define (upply a b cmp . fs)
(let ([arm-f (apply compose fs)])
(cmp (arm-f a) (arm-f b))))
;; Shamelessly ripped from https://wingolog.org/archives/2013/02/25/on-generators
(define (make-generator f)
(define tag (make-prompt-tag))

View File

@ -64,6 +64,11 @@
(define value (iterate 2 1+ 3))
(assert-equal 5 value)))
(define-test-suite "upply"
(define-test "test"
(define value (upply -3 5 = abs 1-))
(assert-equal #t value)))
(define-test-suite "generator"
(define-test "test"
(define number-generator