Skip to content

Instantly share code, notes, and snippets.

@rwaldron
Last active December 24, 2015 15:09
Show Gist options
  • Save rwaldron/6817551 to your computer and use it in GitHub Desktop.
Save rwaldron/6817551 to your computer and use it in GitHub Desktop.
Comparing Y Combinator: Scheme vs. ECMAScript 6
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
(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
@gnarf
Copy link

gnarf commented Oct 4, 2013

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