So the p-cons procedure takes x and y as input and returns an anonymous procedure that takes z as input (and remembers x and y?) What I'm struggling to understand is when I run this in REPL:
(p-car (p-cons 1 2))
it returns 1, and 2 with p-cdr, which is what they are intended to do.However I just can't understand how they are able to access the values of the p-cons procedure? Can someone explain how this works and what I might not be grasping fully? Here are the procedures:
(define (p-cons x y)
(lambda (z) (z x y)))
(define (p-car proc)
(proc (lambda (x y) x)))
(define (p-cdr proc)
(proc (lambda (x y) y)))