灯下 登录
计算机科学 / SICP / 2.2.2 Hierarchical Structures

Exercise 2.28 · 习题

Exercise 2.28: Write a procedure fringe
that takes as argument a tree (represented as a list) and returns a list whose
elements are all the leaves of the tree arranged in left-to-right order. For
example,

(define x
(list (list 1 2) (list 3 4)))

(fringe x)
(1 2 3 4)

(fringe (list x x))

(1 2 3 4 1 2 3 4)

练习 2.28:写一个过程 fringe,它以一棵树(用表表示)为参数,返回一个表,其元素是该树所有的叶子,按从左到右的顺序排列。例如,

(define x
(list (list 1 2) (list 3 4)))

(fringe x)
(1 2 3 4)

(fringe (list x x))
(1 2 3 4 1 2 3 4)

Racket #lang sicp
(define x
 (list (list 1 2) (list 3 4)))

(fringe x)
(1 2 3 4)

(fringe (list x x))
(1 2 3 4 1 2 3 4)