Newsgroups: comp.lang.dylan
Path: cantaloupe.srv.cs.cmu.edu!europa.chnt.gtegsc.com!newsxfer.itd.umich.edu!agate!news.ucdavis.edu!csus.edu!netcom.com!netcom8.netcom.com!haahr
From: haahr@netcom.com (Paul Haahr)
Subject: Re: FIP on tree structures
In-Reply-To: krey@zeus.gmd.de's message of 16 Jun 1995 20:58:47 GMT
To: krey@zeus.gmd.de (Juergen Krey)
Message-ID: <HAAHR.95Jun19093911@netcom8.netcom.com>
Sender: haahr@netcom8.netcom.com
Organization: NETCOM On-line services
References: <3rsra7$m7v@omega.gmd.de>
Date: Mon, 19 Jun 1995 08:39:11 GMT
Lines: 38

Juergen Krey <krey@zeus.gmd.de> wrote:

> Does it make sense to define a forward-iteration-protocol on tree-like,
> i.e. recursive data-structures?

It makes sense to define forward-iteration-protocol on anything that
behaves like a collection.  In fact, it's required that you do.

Do your trees associate keys with values, which is a typical use for
tree-like data structures?  If so, they're a natural subclass of
<explicit-key-collection>.  Do they (conceptually) associate small
integers with some elements?  If so, it's a <sequence>.  But if there is
no key/element association, it's probably not the right thing to use as
a Dylan <collection> or with the iteration protocol.  Notably, sets
don't fit as easily into the Dylan collection heterarchy as one might
like.

Assuming that your <tree> is an <explicit-key-collection>, you then have
to decide what forward means.  Is it breadth-first or depth-first?  Is
it pre-, post-, or (for binary trees) in-order?

(There have been suggestions to extend the for construct to support a
``using'' or ``by'' clause along the lines of

	for (node in tree using postorder-iteration-protocol) ...

but I don't think that was accepted.)

> [...]
> But does anyone suppose any fip-protocol and the appropriate patterns
> for element, element-setter, remove-element, and insert-element
> methods?

Remove-element and insert-element are not parts of the iteration
protocol.  (Those operations are provided by differently named generic
functions.)

Paul
