SHARE
TWEET

Untitled

a guest Jul 17th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. (define (square x) (* x x))
  3.  
  4. (define (tree-map f tree)
  5.   (cond ((null? tree) null)
  6.     ((not (pair? tree)) (f tree))
  7.     (else (cons (tree-map f (car tree))
  8.             (tree-map f (cdr tree))))))
  9.  
  10. (define (square-tree tree)
  11.   (tree-map square tree))
  12.  
  13. (define x (list (list 1 (list 2 (list 3 4) 5) (list 6 7))))
  14.  
  15. (display x)
  16. (newline)
  17. (display (square-tree x))
  18. (newline)
RAW Paste Data
Top