Last active
May 30, 2016 23:53
-
-
Save ndpar/85ba6eb84d2ff691f61e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Y = { f -> | |
{ x -> x(x) } { x -> f { y -> x(x)(y) } } | |
} | |
def triangular = Y { f -> | |
{ n -> n == 0 ? 0 : n + f(n - 1) } | |
} | |
triangular(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define U | |
(λ (f) (f f))) | |
(define Θ | |
((λ (f) (f f)) | |
(λ (g) (λ (f) | |
(f (λ (x) | |
(((g g) f) x))))))) | |
(define F | |
(λ (f) | |
(U (λ (self) | |
(f (λ (x) | |
((self self) x))))))) | |
(define G | |
(λ (f) | |
(f (λ (x) | |
((G f) x))))) | |
(define Y | |
(λ (f) | |
((λ (g) (g g)) | |
(λ (g) | |
(f (λ (x) ((g g) x))))))) | |
(define mk-len | |
(λ (rlen) | |
(λ (lst) | |
(cond | |
[(empty? lst) 0] | |
[else (+ 1 (rlen (rest lst)))])))) | |
(module+ test | |
(require rackunit) | |
(check = ((Θ mk-len) '(1 2 3 4 5)) 5) | |
(check = ((F mk-len) '(1 2 3 4 5)) 5) | |
(check = ((G mk-len) '(1 2 3 4 5)) 5) | |
(check = ((Y mk-len) '(1 2 3 4 5)) 5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment