Feedback Corrected definition of "atom?"; left "reduce-tree" as is 

Forum: Com Sci 221, U Chicago, Autumn 2001, Old Classwork
Re: News Assignment #7 due Monday, 19 November (Mike O'Donnell)
Re: Question A few questions (Ben Wolfson)
Date: 2001, Nov 13
From: Mike O'Donnell <odonnell@cs.uchicago.edu>

In the statement of problem two, you define (atom x) as (not pair? x); shouldn't it be (not (pair? x))?
Yes. I just made that correction to the problem statement.

in problem two, in the definition of reduce-tree, one of the lines (in the true-branch of the cond) has (atomval treein), a function application, where it looks like to maintain symmetry with nested-reduce, and the way "atomval" suggests that it won't be treated as a fuction, it should be something like '(atomval intree) or (cons atomval intree) or something like that. Is that right?
No, in this case I had it right on my first try. The idea of reduce-tree is to think of a binary tree as an expression built up from atomic symbols and the dotted-pair operation. atomval is a 1-argument function that interprets each atomic symbol as something with a value, and op is a 2-argument function corresponding to the dotted-pair operation.

You might argue that reduce and nested-reduce on lists should also interpret atomic symbols, instead of leaving them alone. But the natural recursive definition of the list type does not include atomic symbols as lists, while the natural recursive definition of the binary tree type does include atomic symbols as trees with only one node. So, I think it's slightly more natural to leave atomic symbols unchanged when reducing lists, but evaluate them through a function atomval when reducing trees.

Your proposed variation is reasonable, and there are a lot of other interesting variations to explore, particularly ones that pass some information on the context down to each application of op. But my reduce-tree is better suited for an elegant definition of nested-reduce. To get the same effect with your (cons atomval intree) idea ('(atomval intree) isn't quite what you want, since the "intree" is quoted, and won't get treated as a function parameter), you have to put some clumsy conditional behavior into your op argument. And I think to produce a completely unrestricted implementation of nested-reduce you have to use a corresponding form, such as (listval intree) in the output from your op function to mark the things that are not values of atomic symbols, and then you have to remove the listval mark from the final result, which requires slightly more than just an application of reduce-tree. With my version, you just apply reduce-tree to a couple of simple arguments and out pops nested-reduce




Mike O'D.


Messages

to: "Corrected definition of "atom?"; left "reduce-tree" as is"