sicp 2.31

Exercise 2.31.  Abstract your answer to exercise 2.30 to produce a procedure tree-map with the property that square-tree could be defined as

 

 

(define (square-tree tree) (tree-map square tree))

 

(define (tree-map operation tree)
  (map (lambda (sub-tree)
         (if (pair? sub-tree)
             (tree-map operation sub-tree)
             (operation sub-tree)))
       tree))

(define (square-tree tree) (tree-map square tree))

(define (square x)
  (* x x))
 

你可能感兴趣的:(SICP)