Last active
December 24, 2015 15:09
-
-
Save rwaldron/6817551 to your computer and use it in GitHub Desktop.
Comparing Y Combinator: Scheme vs. ECMAScript 6
This file contains 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
let Y = | |
(fn => (f => f(f)) | |
(f => fn((...args) => f(f)(...args)))); | |
let fac = | |
Y(f => (n => | |
(n <= 2 ? | |
n : | |
n * f(n - 1)))); | |
fac(5); // 120 |
This file contains 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 (Y f) | |
((lambda (x) (x x)) | |
(lambda (g) | |
(f (lambda args (apply (g g) args)))))) | |
(define fac | |
(Y | |
(lambda (f) | |
(lambda (x) | |
(if (< x 2) | |
1 | |
(* x (f (- x 1)))))))) | |
(fac 5) ; 120 |
I honest to god hate the fat-arrow.
Don't worry @leostera, the fat-arrow will never hear you, or be hurt or damaged by your hateful attitude.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why let instead of const?