灯下 登录
计算机科学 / SICP / 2.1.3 What Is Meant by Data?

Exercise 2.4 · 习题

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 1.1.5.)

练习 2.4:这里是序对的另一种过程性表示。对于这种表示,请验证对任意对象 x 和 y,(car (cons x y)) 的结果都是 x。

(define (cons x y)
(lambda (m) (m x y)))

(define (car z)
(z (lambda (p q) p)))

cdr 的对应定义是什么?(提示:为了验证其正确性,请利用第 1.1.5 节的代换模型。)

Racket #lang sicp
(define (cons x y)
 (lambda (m) (m x y)))

(define (car z)
 (z (lambda (p q) p)))