Skip to content

Instantly share code, notes, and snippets.

@DNNX DNNX/true.rb
Created May 26, 2011

Embed
What would you like to do?
True cons/car/cdr in ruby
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
pair = cons(1, "a")
puts car(pair) #=> 1
puts cdr(pair) #=> a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.