Created
May 31, 2012 18:49
-
-
Save dmitryn/2845359 to your computer and use it in GitHub Desktop.
Lambda calculus
This file contains hidden or 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
| def cons(x,y) | |
| lambda {|m| | |
| m.call(x, | |
| y, | |
| lambda {|n| x = n}, | |
| lambda {|n| y = n} | |
| ) | |
| } | |
| end | |
| def car(x) | |
| x.call( | |
| lambda {|a, d, sa, sd| a} | |
| ) | |
| end | |
| def cdr(x) | |
| x.call( | |
| lambda {|a, d, sa, sd| d} | |
| ) | |
| end | |
| def set_car!(x, y) | |
| x.call( | |
| lambda {|a, d, sa, sd| sa.call(y)} | |
| ) | |
| end | |
| def set_cdr!(x, y) | |
| x.call( | |
| lambda {|a, d, sa, sd| sd.call(y)} | |
| ) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment