[closer-devel] Recursive types

Pascal Costanza pc at p-cos.net
Mon Jul 21 15:35:55 UTC 2008


On 21 Jul 2008, at 17:04, Marco Antoniotti wrote:

>
> On Jul 13, 2008, at 17:54 , Pascal Costanza wrote:
>
>> As far as I can tell, a modification of deftype should be  
>> sufficient, such that (deftype name) "announces" a type without  
>> saying yet what it will be.
>>
>> Maybe write a first draft of such a CDR, and then ask the vendors  
>> what they think, they should know best whether and where this  
>> hurts...
>
> That is my intention.  However, just modifying DEFTYPE already  
> raises issues.  See the following...
>
> (deftype foo)
>
> (deftype bar)
>
> (deftype foo-or-bar () '(or foo bar))
>
>
> Now, all these types are actually "empty" from a set-theoretic point  
> of view.

Hm, well, my idea was that (deftype foo) only "announces" the type foo  
but doesn't define it yet, so that you can do things like this:

(deftype arc) ;; not yet defined, but tells the compiler that it will  
be defined later

(defstruct node
   content
   (left nil :type (or null arc))
   (right nil :type (or null arc))

(defstruct arc ;; now it is defined as a struct
   (source nil :type (or null node))
   (sink nil :type (or null node)))

The tricky part is in (a) specifying where an announced but not yet  
defined type is allowed to be used and (b) specifying what is the  
latest point in time when an announced type must effectively be  
defined (like, for example, performing the first type test with the  
given type - it's unclear to me what the most adequate criterion  
should be here).

> Also, note the following interesting behavior on LWM and ACL 8.1 (I  
> have not tested other implementations).
>
> CL-USER 13 > (deftype gnao ())
> GNAO
>
> CL-USER 14 > (typep nil 'gnao)
> NIL
>
> CL-USER 15 > (defstruct gnao a s d)
> GNAO
>
> CL-USER 16 > (make-gnao)
> #S(GNAO :A NIL :S NIL :D NIL)
>
> CL-USER 17 > (typep (make-gnao) 'gnao)
> NIL
>
> CL-USER 18 > (type-of (make-gnao))
> GNAO
>
> AFAIAC this is not good.   And the culprit is the DEFTYPE that does  
> introduce an extra namespace in CL without really defining what is  
> in there and how I can manipulate it.

Why? You got what you asked for. (deftype gnoa ()) has an empty body,  
so by default it returns nil, which happens to be the type that  
doesn't have any instances.

Furthermore, ANSI CL doesn't say anything about type redefinition, so  
we are in unspecified realm here. ANSI CL only says something about  
class redefinition, but that doesn't change the corresponding types.  
The CLOS MOP says that changing the metaclass of a class is forbidden,  
so you can't change (the kind of) types using the CLOS MOP either.


Pascal

-- 
Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium






-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/closer-devel/attachments/20080721/fa573e42/attachment.html>


More information about the closer-devel mailing list