Feedback Examples using reduce-tree 

Forum: U Chicago, Com Sci 221, autumn 2000
Re: News Assignment #7, due Monday 20 November (Mike O'Donnell)
Re: Question Question about problem 2 (Ben Johnson)
Date: 2000, Nov 18
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

For example,

(reduce-tree + (lambda (x) 1))
is a function that counts the leaves on a tree (including the nils at the ends of lists).
(reduce-tree append (lambda (x) (list x))
flattens a tree into a list of its leaves (including nils).
(reduce-tree + (lambda (x) (if (number? x) x 0)))
sums up all the numbers in a tree, ignoring things that aren't numbers.
(reduce-tree (lambda (x y) (+ (max x y) 1)) (lambda (x) 0))
counts the height of a tree.

I hope that you can figure out other uses by analogy. More systematically, the first argument to reduce-tree is a function of 2 arguments, used to combine the value of a left subtree with the value of a right subtree. The second argument to reduce-tree is a function of 1 argument, used to calculate the value of a leaf.

Try to find two very simple arguments to reduce-tree that produce the identity function. If you can do that, you probably understand reduce-tree pretty thoroughly.

It would be great if other people would post amusing examples.



Mike O'D.


Messages

1. Question reduce and reduce-tree question by Michael C. Brizic, 2000, Nov 18
(_ Idea tree args by dave, 2000, Nov 18
(_ Agree reduce-tree doesn't apply to trees, but it's output does by Mike O'Donnell, 2000, Nov 18
(_ Question Another question on #2 by Ben Johnson, 2000, Nov 19
(_ Feedback Your reduce equivalent to mine, test it with identity by Mike O'Donnell, 2000, Nov 19

to: "Examples using reduce-tree"