内容 2.1 Introduction to Data Abstraction · 78
练习 自检推理
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 节的代换模型。)
SICP source code scheme
(define (cons x y)
(lambda (m) (m x y)))
(define (car z)
(z (lambda (p q) p))) 我的笔记 自动保存