Sunday, June 7, 2009

Ex-2.35

basically with map we create a flat list containing number of leaves in each subtree and then accumulate is used to sum them up.
(define (count-leaves t)
(accumulate
+ 0
(map (lambda (x)
(if (pair? x)
(count-leaves x) 1)) t)))

No comments:

Post a Comment