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))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define nil '()) | |
| (define (tree-map proc tree) | |
| (cond | |
| ((null? tree) | |
| nil) | |
| ((not (pair? tree)) | |
| (proc tree)) | |
| (else | |
| (cons | |
| (tree-map proc (car tree)) | |
| (tree-map proc (cdr tree)))))) | |
| (define (square x) (* x x)) | |
| (tree-map square (list 1 (list 2 (list 3 4) 5) (list 6 7)))) | |