(define (pair a b)
(lambda (f) (f a b)))
(define (fst x) .... )
'fst' is supposed to return a when i call (fst(pair 1 2))
I know that function (f a b) is stored in 'x' when i call (fst(pair 1 2)) How can I extract 'a' out? Any tips?
I tried using (car x) and (cdr x), but x is clearly not a list.
Edit: I ended up with this:
(define (fst x) (x (lambda (p q) p)))
(define (snd x) (x (lambda (p q) q)))
I am really new to scheme programming so i am still trying to understand how the compiler works. So, from this i learnt that if the "lambda" keyword is used after a function. so like (x (lambda (p q)), this actually extracts the p and q from x. Am i correct?
Thanks.