Skip to content

Instantly share code, notes, and snippets.

@cfx
Created March 14, 2012 12:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfx/2036253 to your computer and use it in GitHub Desktop.
Save cfx/2036253 to your computer and use it in GitHub Desktop.
Y combinator in ruby
lambda { |m|
lambda { |f| f.call(f) }.call(
lambda { |f|
m.call(lambda { |x| f.call(f).call(x) })}) }
e.g
lambda { |m|
lambda { |f| f.call(f) }.call(
lambda { |f|
m.call(lambda { |x| f.call(f).call(x) })}) }.call(
lambda { |silnia|
lambda { |n|
if n == 0
1
else
n * silnia.call(n-1)
end }}).call(4)
=> 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment