(define (tree-map proc tree)
(map (lambda (sub-tree)
(cond ((null? sub-tree) ())
((not (pair? sub-tree)) (proc sub-tree))
(else (tree-map proc sub-tree))))
tree))
(define square
(lambda (x) (* x x)))
(define (square-tree tree) (tree-map square tree))
(square-tree
(list 1
(list 2 (list 3 4) 5)
(list 6 7)))
SICP 练习2.31 tree-map
最新推荐文章于 2024-09-28 08:36:25 发布