Solution for exercise 2.31 of SICP:

(define (square x) (* x x)) (define (tree-map function tree) (map (lambda (subtree) (if (pair? subtree) (tree-map function subtree) (function subtree))) tree)) (define (square-tree tree) (tree-map square tree)) (square-tree (list 1 (list 2 (list 3 4) 5) (list 6 7)))