Skip to content

Instantly share code, notes, and snippets.

@carlism
Created July 12, 2013 17:57
Show Gist options
  • Save carlism/5986413 to your computer and use it in GitHub Desktop.
Save carlism/5986413 to your computer and use it in GitHub Desktop.
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