Newsgroups: comp.lang.dylan
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!news.mathworks.com!uunet!newsflash.concordia.ca!CC.UMontreal.CA!IRO.UMontreal.CA!saguenay.iro.umontreal.ca!premont
From: premont@IRO.UMontreal.CA (Patrick Premont)
Subject: Re: Null objects ?
Message-ID: <D77LLn.3Cy@IRO.UMontreal.CA>
Sender: news@IRO.UMontreal.CA
Organization: Universite de Montreal
X-Newsreader: TIN [version 1.2 PL2]
References: <Pine.3.89.9504172101.A1898-0100000@boavista.snafu.de>
Date: Tue, 18 Apr 1995 02:29:46 GMT
Lines: 49

Michael Erdmann (erdmann@boavista.snafu.de) wrote:

: I have defined my selft a class called <tree> with the slots left, right 
: and item. I am trying to do the same thing as above in dylan. The code 
: fragment looks like this:

: define class <binary-tree> (<object>)
:   slot left  :: <binary-tree>, init-keyword: left:  ;
:   slot right :: <binary-tree>, init-keyword: right: ;
:   slot item , init-keyword: item: ;
: end class <binary-tree>;

: define method insert( a, t :: <binary-tree> )

:     let result = compare (a, item(t));

:     case 
:       result < 0 =>
: 	if( left(t) )
: 	  insert(a,left(t));
: 	else
: 	  left(t) := make(<binary-tree>,item: a );
: 	end if;
:       result > 0 =>
: 	if( right(t) )
: 	  insert(a,left(t));
: 	else
: 	  right(t) := make(<binary-tree>,item: a );
: 	end if;
:       result == 0 =>
: 	t;
:     end case;
: end method insert;
: 	
: But mindy complains about unbound slots when i am checking left or right. 
: Is there any way in order to figure out if the left or right slot has
: been assigned (something like a NIL), or should i take a totaly different 
: approach to it ?

You expect left(t) or rigth(t) to be #f when there is no subtree in that
slot but you do not initialize these slots when you write
make(<binary-tree>, item: a).

Just add ", init-value: #f" to left and right slot specifications.
And to prevent further occurences of this problem, you should make the
"init-keyword: item:" a "required-init-keyword: item:" or choose an
appropriate init-value for this slot.

Patrick Premont
