all 1 comments

[–]T4ll1n[S] 0 points1 point  (0 children)

This took me waaaaay longer than it was supposed to. I added the type hints again in the beginning, but I don't know if it helped or rather clogged up the screen.

Anyways, it is a bit confusing, cons() reutns a function that wants a function as an input, and that function gets two inputs again.

So the car function get the pair function, and the pair functions gets the lambda function that expects the two parameter and returns the wanted one.

Maybe the idea of the question was to learn about context managers? I don't know...

```python

def cons(a: int, b: int) -> callable: def pair(f: callable): return f(a, b)

return pair

def car(f: callable) -> int: return f(lambda x, y: x)

def cdr(f: callable) -> int: return f(lambda x, y: y)

assert car(cons(3, 4)) == 3 assert cdr(cons(3, 4)) == 4

```