CS 6520 HW 4

Here's a data definition:

; A num-tree is either
;  - num
;  - (make-tree num num-tree num-tree)
(define-struct tree (v l r))

  1. Implement inflate-tree, which produces a tree by adding one to every number in a given tree.
  2. Implement grow-tree, which replaces every leaf num in the tree with (make-tree num 0 0).
  3. Abstract inflate-tree and grow-tree to produce a more general tree-mapping function, map2-tree. Unlike map for lists, map2-tree needs two function arguments.
  4. Implement sum-tree, which sums all of the numbers in a tree.
  5. Generalize map2-tree and sum-tree to produce fold-tree.
  6. Generalize the num-tree data definition to X-tree and provide new contracts for map2-tree and fold-tree that are as general as possible.


Last update: Friday, February 6th, 2004
mflatt@cs.utah.edu