内容 3.3 Modeling with Mutable Data · 215
练习 自检推理
Exercise 3.13: Consider the following
make-cycle procedure, which uses the last-pair procedure defined
in Exercise 3.12:
(define (make-cycle x)
(set-cdr! (last-pair x) x)
x)
Draw a box-and-pointer diagram that shows the structure z created by
(define z (make-cycle (list 'a 'b 'c)))
What happens if we try to compute (last-pair z)?
练习 3.13:考虑以下 make-cycle 过程,它使用了练习 3.12 中定义的 last-pair 过程:
(define (make-cycle x)
(set-cdr! (last-pair x) x)
x)
画出由以下语句创建的结构 z 的序对指针图:
(define z (make-cycle (list 'a 'b 'c)))
如果我们试图计算 (last-pair z),会发生什么?
SICP source code scheme
(define (make-cycle x)
(set-cdr! (last-pair x) x)
x) SICP source code scheme
(define z (make-cycle (list 'a 'b 'c))) 我的笔记 自动保存