Last active
November 16, 2018 04:45
-
-
Save woodRock/72ba43000a0bbe48ab36504c21b0111b to your computer and use it in GitHub Desktop.
cons(a, b) constructs a pair, and car(pair) and cdr(pair) returns the first and last element of that pair. For example, car(cons(3, 4)) returns 3, and cdr(cons(3, 4)) returns 4. Given this implementation of cons: def cons(a, b): def pair(f): return f(a, b) return pair Implement car and cdr
This file contains 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 f: f(a, b) | |
def car(f): | |
return f(lambda a, b: a) | |
def cdr(f): | |
return f(lambda a, b: b) | |
a, b = (int(n) for n in input().split(',')) | |
print(car(cons(a, b))) | |
print(cdr(cons(a, b))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment