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?

19th Apr 2020, 4:14 PM
Md. Mursalatul Islam Pallob
Md. Mursalatul Islam Pallob - avatar
6 Respostas
+ 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)
19th Apr 2020, 4:23 PM
Eddie 🇦🇲
Eddie 🇦🇲 - avatar
+ 1
The problem asks you to write car(pair) and cdr(pair) functions as they described them.
19th Apr 2020, 5:10 PM
Eddie 🇦🇲
Eddie 🇦🇲 - avatar
0
Sir will you please explain what the problem asking me to do please ... I dont understand the question... Thanks .....
19th Apr 2020, 4:31 PM
Md. Mursalatul Islam Pallob
Md. Mursalatul Islam Pallob - avatar
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))
19th Apr 2020, 4:52 PM
rodwynnejones
rodwynnejones - avatar
0
Check this, I think it will help you to understand. https://en.wikipedia.org/wiki/CAR_and_CDR
19th Apr 2020, 5:15 PM
Eddie 🇦🇲
Eddie 🇦🇲 - avatar
0
Thanks sir for your valuable comments .....
19th Apr 2020, 5:17 PM
Md. Mursalatul Islam Pallob
Md. Mursalatul Islam Pallob - avatar