Skip to content

Instantly share code, notes, and snippets.

@woodRock
Last active November 16, 2018 04:45
Show Gist options
  • Save woodRock/72ba43000a0bbe48ab36504c21b0111b to your computer and use it in GitHub Desktop.
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
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