Chapter 2, Building Abstractions with Data

Section - 2.2 - Hierarchical Data and the Closure Property

Exercise 2.31


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#lang sicp

(define (tree-map proc tree)
  (map
      (lambda (x)
         (if (not (pair? x))
             (proc x)
             (tree-map proc x)
         )
      )  
      tree
  )
)

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

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