main
Inga 🏳‍🌈 11 months ago
parent 7520a58aec
commit b0a3de96b4
  1. 11
      day01-hard/main.scm

@ -25,9 +25,20 @@
(define (prepend first-value) (lambda (rest) (cons first-value rest)))
;=============== combinators ======================
(define (Y f) (f (lambda (x) ((Y f) x))))
(define (Y2 f) (f (lambda (x y) ((Y2 f) x y))))
(assert-eq "Y test 1 (factorial) failed"
120
((Y (lambda (f) (lambda (n) (if (= n 0) 1 (* n (f (- n 1))))))) 5))
(assert-eq "Y2 test 1 (pascal triangle) failed"
35
((Y2 (lambda (f) (lambda (a b)
(if (= a 0) 1 (if (= b 0) 1 (+ (f (- a 1) b) (f a (- b 1))))))))
3 4))
(define (reduce-right initial reducer) (Y
(lambda (f) (lambda (values)
(if (null? values) initial (reducer (car values) (f (cdr values))))))))

Loading…
Cancel
Save