Created
November 21, 2013 01:23
-
-
Save sgrif/7574451 to your computer and use it in GitHub Desktop.
Z Combinator in elixir
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
z = fn | |
f -> fn | |
x -> f.(fn y -> x.(x).(y) end) | |
end.(fn | |
x -> f.(fn y -> x.(x).(y) end) | |
end) | |
end | |
add_squares = z.(fn | |
f -> fn | |
[n|ns] -> n*n + f.(ns) | |
[] -> 0 | |
end | |
end) | |
IO.puts "#{add_squares.([1, 2, 5])}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want the same name inside the function, this would also work.