Tree map

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))

There are no comments yet.

Authentication required

You must log in to post a comment.

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

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

(define tree (list 1 (list 2 (list 3 4) 5) (list 6 7)))

(check-equal? (square-tree tree)  '(1 (4 (9 16) 25) (36 49)))