内容 2.2 Hierarchical Data and the Closure Property · 105
练习 自检推理
Exercise 2.27: Modify your reverse
procedure of Exercise 2.18 to produce a deep-reverse procedure
that takes a list as argument and returns as its value the list with its
elements reversed and with all sublists deep-reversed as well. For example,
(define x
(list (list 1 2) (list 3 4)))
x
((1 2) (3 4))
(reverse x)
((3 4) (1 2))
(deep-reverse x)
((4 3) (2 1))
练习 2.27:修改你在练习 2.18 中编写的 reverse 过程,产生一个 deep-reverse 过程,它以一个表作为参数,返回的值是将该表中所有元素的顺序颠倒、并且所有子表也深度颠倒之后的表。例如,
(define x
(list (list 1 2) (list 3 4)))
x
((1 2) (3 4))
(reverse x)
((3 4) (1 2))
(deep-reverse x)
((4 3) (2 1))
SICP source code scheme
(define x
(list (list 1 2) (list 3 4)))
x
((1 2) (3 4))
(reverse x)
((3 4) (1 2))
(deep-reverse x)
((4 3) (2 1)) 我的笔记 自动保存