From: Julian St.
Subject: General declaration question
Date: 
Message-ID: <5rn0zgq3x2.fsf@blitz.comp.com>
Hello,

Consider the following structure (hmm... no better example in mind...):

(defstruct node
   parent
   child1
   child2)

The field parent (and the children) can obviously contain either
another node or nil indicating no parent, child whatever.

When adding type declarations in the last stage of an program, shall I
type parent to be of type (or node null) ? Looks a bit awkward to me.

Can somebody please clarify this? Thanks in advance.

Regards,
Julian St.

From: Barry Margolin
Subject: Re: General declaration question
Date: 
Message-ID: <6%D08.13$rW4.243132@burlma1-snr2>
In article <··············@blitz.comp.com>,
Julian St. <·········@gmx.net> wrote:
>Consider the following structure (hmm... no better example in mind...):
>
>(defstruct node
>   parent
>   child1
>   child2)
>
>The field parent (and the children) can obviously contain either
>another node or nil indicating no parent, child whatever.
>
>When adding type declarations in the last stage of an program, shall I
>type parent to be of type (or node null) ? Looks a bit awkward to me.
>
>Can somebody please clarify this? Thanks in advance.

You could define the following type macro:

(deftype nil-or-type (type)
  `(or ,type null))

and then use (nil-or-type node).

Declarations like this are not likely to buy you much, so you could just
forget it entirely.  If you want something of benefit to the human reader,
use a comment.

-- 
Barry Margolin, ······@genuity.net
Genuity, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
From: Thomas F. Burdick
Subject: Re: General declaration question
Date: 
Message-ID: <xcvpu4c2i89.fsf@apocalypse.OCF.Berkeley.EDU>
Barry Margolin <······@genuity.net> writes:

> Declarations like this are not likely to buy you much, so you could just
> forget it entirely.  If you want something of benefit to the human reader,
> use a comment.

Well, they're not likely to buy you much, portably.  And they're not
likely to buy you performance.  But for the CMUCL user, they're likely
to buy you a type check, which can be nice.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Janis Dzerins
Subject: Re: General declaration question
Date: 
Message-ID: <a1v2ng$mqm$1@milzis.latnet.lv>
·········@gmx.net (Julian St.) writes:

> Hello,
> 
> Consider the following structure (hmm... no better example in mind...):

You could try and show us the real code that bugs you.

> (defstruct node
>    parent
>    child1
>    child2)
> 
> The field parent (and the children) can obviously contain either
> another node or nil indicating no parent, child whatever.
> 
> When adding type declarations in the last stage of an program, shall I
> type parent to be of type (or node null) ? Looks a bit awkward to me.

What is awkward there?

And -- are you really sure you need to add declarations here?

-- 
Janis Dzerins

  Eat shit -- billions of flies can't be wrong.