Instantly share code, notes, and snippets.

Embed
What would you like to do?
Cons, car and cdr in Python
def cons(x,y):
return lambda pick: x if pick == 1 else y
def car(cons):
return cons(1)
def cdr(cons):
return cons(2)
def cons(a,b):
return lambda m: m(a,b)
def car(cons):
return cons(lambda a,b: a)
def cdr(cons):
return cons(lambda a,b: b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment