Created
September 14, 2011 05:21
-
-
Save fadeev/1215910 to your computer and use it in GitHub Desktop.
Cons, car and cdr in Python
This file contains hidden or 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): | |
| return lambda pick: x if pick == 1 else y | |
| def car(cons): | |
| return cons(1) | |
| def cdr(cons): | |
| return cons(2) |
This file contains hidden or 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(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