0
Please help me to understand this problem !!
I found a problem on a website. But I can't understand the problem. This problem was asked by Jane Street. "" 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. "" . please tell me what I have to do? What does it want me to do?
6 ответов
+ 2
def car(pair):
def return_first(a, b):
return a
return pair(return_first)
def cdr(pair):
def return_last(a, b):
return b
return pair(return_last)
+ 1
The problem asks you to write car(pair) and cdr(pair) functions as they described them.
0
Sir will you please explain what the problem asking me to do please ...
I dont understand the question...
Thanks .....
0
goggle "closures" aka nested function.
def cons(a, b):
def pair(f):
return f(a, b)
return pair
car = cons(3, 4)
cdr = cons(3, 4)
print(car(min))
print(cdr(max))
0
Check this, I think it will help you to understand.
https://en.wikipedia.org/wiki/CAR_and_CDR
0
Thanks sir for your valuable comments .....