Exercise 2.4. Here is an alternative procedural representation of pairs. For this representation, verify that (car (cons x y)) yields x for any objects x and y.
(define (cons x y)
(lambda (m) (m x y)))
(define (car z)
(z (lambda (p q) p)))
What is the corresponding definition of cdr? (Hint: To verify that this works, make use of the substitution model of section 1.1.5.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (cons x y) | |
| (lambda (m) (m x y))) | |
| (define (car z) | |
| (z (lambda (p q) p))) | |
| (define (cdr z) | |
| (z (lambda (p q) q))) | |
| ;; ((lambda (m) (m x y)) (lambda (p q) p)) | |
| ;; ((lambda (p q) p) x y) | |
| ;; x | |