Due: Thursday, March 17th, 2011 9:10am
Convert the following sum function (which sums numbers pairwise from two same-length lists, producing a new list) to tail form:
(define (sum a b)
(cond
[(empty? a) empty]
[else (cons (+ (first a) (first b))
(sum (rest a) (rest b)))]))Convert the following sum-trees function (which sums numbers pairwise from two same-shaped trees, producing a new tree) to tail form:
(define (sum-trees a b)
(cond
[(empty? a) empty]
[else (make-tree
(sum-trees (tree-left a) (tree-left b))
(+ (tree-val a) (tree-val b))
(sum-trees (tree-right a) (tree-right b)))]))| Last update: Thursday, April 7th, 2011mflatt@cs.utah.edu |