Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jorinvo
Last active August 29, 2015 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jorinvo/a054f08b4d345538e29e to your computer and use it in GitHub Desktop.
Save jorinvo/a054f08b4d345538e29e to your computer and use it in GitHub Desktop.
JS version of code from Jim Weirichs Talk on Lambda Calculus (https://www.youtube.com/watch?v=FITJMJjASUs)
// Y Combinator
// makes the recursion
(function(improver) {
return (function(gen) { return gen(gen) })(
function(gen) {
return improver(function(v) {
return gen(gen)(v)
})
}
)
})(
// this part is the condition for the factorial
function(partial) {
return function(n) {
return n === 0 ? 1 : n * partial(n - 1)
}
}
// pass any number here to get its factorial
)(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment