Created
July 12, 2013 17:57
-
-
Save carlism/5986413 to your computer and use it in GitHub Desktop.
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
def cons(x,y) | |
->(m){ m.call(x, y) } | |
end | |
def car(z) | |
z.call( ->(p, q) {p} ) | |
end | |
def cdr(z) | |
z.call( ->(p, q) {q} ) | |
end | |
def list(head = nil, *tail) | |
cons(head, list(*tail)) if head | |
end | |
x = cons "first", "second" | |
puts car x | |
puts cdr x | |
y = cons "outer", x | |
puts car y | |
puts car cdr y | |
puts cdr cdr y | |
z = list(1, 2, 5, 42, "test", 6) | |
puts car cdr cdr cdr z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment