http://erdos.csie.ncnu.edu.tw/~klim/scheme/lisp-1062.htmlexercise 7: mapping over trees
•Refer to exercise 2.31.
解答:
(define l (list 1 (list 2 3 (list 4 5))))
(define (sq x) (* x x))
(define (tree-map f tree)
(cond ((null? tree)
'())
((not (pair? tree))
(f tree))
(else
(cons (tree-map f (car tree))
(tree-map f (cdr tree))))))
執行結果:
沒有留言:
張貼留言