Skip to content

Instantly share code, notes, and snippets.

@DNNX
Created May 26, 2011 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DNNX/993019 to your computer and use it in GitHub Desktop.
Save DNNX/993019 to your computer and use it in GitHub Desktop.
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