Skip to content

Instantly share code, notes, and snippets.

@r3b
Created June 19, 2014 05:34
Show Gist options
  • Save r3b/f9830e37108c84c46ece to your computer and use it in GitHub Desktop.
Save r3b/f9830e37108c84c46ece to your computer and use it in GitHub Desktop.
A Javascript Y-Combinator, with proper symbols.
var Y = function(ƒ) {
return (function(x) {
return ƒ(function λ(y) {
return (x(x))(y);
});
})
(function λ(x) {
return ƒ(function λ(y) {
return (x(x))(y);
});
});
};
var fib = Y(function(ƒ) {
return (function(n) {
return (n == 0 || n == 1) ? n : ƒ(n - 1) + ƒ(n - 2);
});
});
fib(20);
@r3b
Copy link
Author

r3b commented Jun 19, 2014

Because using the unicode symbols makes me feel like I remotely understand what's going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment