From: David B. Lamkins
Subject: Re: Binary Tree
Date: 
Message-ID: <W6WN2.29943$A6.15568214@news1.teleport.com>
In article 
<··················································@library-proxy.airnews.ne
t> , ···@jaguNET.com (Bob) wrote:

> Does anyone have any sample code for constructing a simple binary tree
> using lisp?
>
> Bob
> ···@jaguNET.com

Sure.  Define a node as a cons, so that (cons left right) constructs the
simplest non-empty tree.  Define the rest recursively.

--
David B. Lamkins <http://www.teleport.com/~dlamkins/>

There are many ways to abbreviate something, but only one way not to.

From: Johan Kullstam
Subject: Re: Binary Tree
Date: 
Message-ID: <upv5jw5le.fsf@res.raytheon.com>
"David B. Lamkins" <········@teleport.com> writes:

> In article 
> <··················································@library-proxy.airnews.ne
> t> , ···@jaguNET.com (Bob) wrote:
> 
> > Does anyone have any sample code for constructing a simple binary tree
> > using lisp?
> 
> Sure.  Define a node as a cons, so that (cons left right) constructs the
> simplest non-empty tree.  Define the rest recursively.

what exactly is a *simple binary tree*?

most of the binary trees i have used have had three elements.  a left,
a right and a data point.  you would use as building block something
like

  (defstruct node left right data)

instead of a cons.

perhaps this is not a *simple* tree and i have my terminology
confused.

-- 
johan kullstam
From: David B. Lamkins
Subject: Re: Binary Tree
Date: 
Message-ID: <Mg5O2.30408$A6.15831740@news1.teleport.com>
In article <·············@res.raytheon.com> , Johan Kullstam 
<········@ne.mediaone.net>  wrote:

> "David B. Lamkins" <········@teleport.com> writes:
>
>> In article
>> <··················································@library-proxy.airnews.ne
>> t> , ···@jaguNET.com (Bob) wrote:
>>
>> > Does anyone have any sample code for constructing a simple binary tree
>> > using lisp?
>>
>> Sure.  Define a node as a cons, so that (cons left right) constructs the
>> simplest non-empty tree.  Define the rest recursively.
>
> what exactly is a *simple binary tree*?
>
> most of the binary trees i have used have had three elements.  a left,
> a right and a data point.  you would use as building block something
> like
>
>   (defstruct node left right data)
>
> instead of a cons.
>
> perhaps this is not a *simple* tree and i have my terminology
> confused.

Of course, you are correct.  Let me explain my line of reasoning.

I assumed that the original poster's question was a homework question; it
had all the earmarks of same: an elementary problem [def: something that's
covered by most Lisp programming books], a request for a solution, and
absence of any indication that the poster had tried to arrive at a solution
before asking for an answer.  (I apologize to the poster if this was in fact
_not_ a homework problem; sadly, your posting really does fit the profile.)

Now, I can empathize with the homework-problem posters up to a point.  My
impression is that few programming instructors understand Lisp well enough
to teach it, and rely on their students to puzzle out a solution using
whatever resources they can call upon.  My own approach as a student was to
find a book, but I can understand not wanting to spend $50 or so on a book
that will only be useful for a few days (I'm guessing that the student's
exposure to Lisp won't extend beyond one or two programming exercises -- at
least not within the realm of his/her educational experience), and I know
that most libraries simply don't have Lisp books in their holdings.

Now, if I'm right about the poster's situation, then a very restricted
subset of Lisp is probably applicable.  I'm assuming that the poster already
knows about CONS, but would have to look up DEFSTRUCT (and might arouse the
suspicions of the instructor with solution based upon DEFSTRUCT or
DEFCLASS).  Under these circumstances, the answer I've given provides a
sufficient basis to develop an appropriate answer for the exercise.  (Just
as you can use a cons to build a tree without data, you can use a cons to
make a node with a datum and a pair of links.)  Granted, it's not what
anyone would do in a real-world program, but it's probably close to what
many programming instructors try to achieve with their Lisp exercises.

Sometimes I wonder why we don't put together a Lisp Homework FAQ.  We could
go through the DejaNews archives, abstract out the five top homework
problems, and present worked solutions.  This would keep us out of the
programming/ethics instructor business, give the students a consistent and
accurate guide to basic information, and put instructors on notice that they
had better come up with some more interesting challenges (which would mean
that they'd have to teach more than the half-dozen primitives most of them
get by with now).

--
David B. Lamkins <http://www.teleport.com/~dlamkins/>

There are many ways to abbreviate something, but only one way not to.
From: Vassil Nikolov
Subject: homework FAQ (Ex: Re: Binary Tree)
Date: 
Message-ID: <7ecll3$ibi$1@nnrp1.dejanews.com>
In article <·······················@news1.teleport.com>,
  "David B. Lamkins" <········@teleport.com> wrote:
(...)
> Sometimes I wonder why we don't put together a Lisp Homework FAQ.  We could
> go through the DejaNews archives, abstract out the five top homework
> problems, and present worked solutions.  This would keep us out of the
> programming/ethics instructor business, give the students a consistent and
> accurate guide to basic information, and put instructors on notice that they
> had better come up with some more interesting challenges (which would mean
> that they'd have to teach more than the half-dozen primitives most of them
> get by with now).

I second that.

This would probably be done in the spirit of `worse is better'
and might one day evolve into _The comp.lang.lisp Primer_.

But my most important point is that I am willing to contribute
(though not via the newsgroup but by e-mail; I appreciate that
Deja News gives me the opportunity to read news, but it is not
terribly convenient for serious collaborative work.)

Everybody should feel free to contact me privately with regard
to this matter.  Otherwise, I might prepare a 0.0 version RSN.

Vassil Nikolov <········@poboxes.com> www.poboxes.com/vnikolov
(You may want to cc your posting to me if I _have_ to see it.)
   LEGEMANVALEMFVTVTVM  (Ancient Roman programmers' adage.)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own