Idea trees vs. lists 

Forum: Com Sci 221, U Chicago, Autumn 2001, Old Classwork
Re: News Assignment #7 due Monday, 19 November (Mike O'Donnell)
Re: Question dynamic scope? and tree representation? (Terry (Sotiria) Lampoudi)
Re: More Re: Tree Representation (Avi Schwab)
Date: 2001, Nov 18
From: Roni Choudhury roni

To answer your final question, the tree /\ a b can be represented by (a.b).

Yes, I agree. I like to think of the construct (a . b) as a node with children a and b. You can thus create trees simply by writing a representation containing dotted pairs.

My problem is now with the concept of a "list". I think I would like to say that the set of lists are exactly those trees whose rightmost child is nil. This is causing me trouble with problem number two, which I'm going to try to explain now, that someone might be able to help me out.

The function ((nested-reduce f v) lst) works by f'ing the car of lst with the cdr of lst. If lst is an atom, then nested-reduce returns that atom, and if lst is null, then nested-reduce returns v. This is important. We have, on an intuitive level, evaluated nil to be v, and this reflects the behavior we want to see in the function.

tree-reduce, as far as I can tell, is quite different. tree-reduce takes a parameter called atomval which tells how to evaluate a leaf of the tree. There is no v parameter that tells what to return when we hit nil, and this is what is confusing me...[flash of insight...quick coding binge...smile]...ok actually I just figured this out. Sorry for the rambling, in this case. I'm posting this anyways, in case it helps someone else come to the same flash of insight that just hit me. Sorry :)

roni


Messages

to: "trees vs. lists"