From: Florian Weimer
Subject: Expanding DEFTYPEs
Date: 
Message-ID: <87fymoltlv.fsf@mid.deneb.enyo.de>
Is it possible to obtain the declaration of a DEFTYPE, based on the
name in that DEFTYPE?

An application for that functionality would be an ECASE variant which
takes a MEMBER type and checks at compile time if the list of symbols
is exhaustive.

From: jayessay
Subject: Re: Expanding DEFTYPEs
Date: 
Message-ID: <m3wtg04dwc.fsf@rigel.goldenthreadtech.com>
Florian Weimer <··@deneb.enyo.de> writes:

> Is it possible to obtain the declaration of a DEFTYPE, based on the
> name in that DEFTYPE?

That isn't specified (as far as I can see).  That would make it
"implementation dependent" (and thus maybe not available...)


OTOH,

> An application for that functionality would be an ECASE variant which
> takes a MEMBER type and checks at compile time if the list of symbols
> is exhaustive.

This should work just fine for your purpose:

(defconstant +foo-type-members+ '(:a :b :c))

(deftype foo () `(member ,@+foo-type-members+))

Now you can use +foo-type-members+ in your code walker as the set of
symbols to check against.

You can wrap the two bits together into a single "defmember-type" or
some such:

(macroexpand-1 '(defmember-type foo :a :b :c))

=> (progn (defconstant +foo-type-members+ '(:a :b :c))
          (deftype foo () `(member ,@+foo-type-members+)))

Or some such.


/Jon

-- 
'j' - a n t h o n y at romeo/charley/november com
From: jayessay
Subject: Re: Expanding DEFTYPEs
Date: 
Message-ID: <m3slqo4d8r.fsf@rigel.goldenthreadtech.com>
jayessay <······@foo.com> writes:

> Florian Weimer <··@deneb.enyo.de> writes:
> 
> > Is it possible to obtain the declaration of a DEFTYPE, based on the
> > name in that DEFTYPE?
> 
> That isn't specified (as far as I can see).  That would make it
> "implementation dependent" (and thus maybe not available...)
> 
> 
> OTOH,
> 
> > An application for that functionality would be an ECASE variant which
> > takes a MEMBER type and checks at compile time if the list of symbols
> > is exhaustive.
> 
> This should work just fine for your purpose:
> 
> (defconstant +foo-type-members+ '(:a :b :c))
> 
> (deftype foo () `(member ,@+foo-type-members+))
> 
> Now you can use +foo-type-members+ in your code walker as the set of
> symbols to check against.
> 
> You can wrap the two bits together into a single "defmember-type" or
> some such:
> 
> (macroexpand-1 '(defmember-type foo :a :b :c))
> 
> => (progn (defconstant +foo-type-members+ '(:a :b :c))
>           (deftype foo () `(member ,@+foo-type-members+)))
> 
> Or some such.

Just saw Pascal's post on this and I think using the plist of the type
symbol is a much better way to go than this constant nonsense.


/Jon

-- 
'j' - a n t h o n y at romeo/charley/november com
From: Kalle Olavi Niemitalo
Subject: Re: Expanding DEFTYPEs
Date: 
Message-ID: <87d5hsyc7f.fsf@Astalo.kon.iki.fi>
Florian Weimer <··@deneb.enyo.de> writes:

> Is it possible to obtain the declaration of a DEFTYPE, based on the
> name in that DEFTYPE?

There is no standard way to do that by introspection after a
COMMON-LISP:DEFTYPE form has been evaluated, but CMUCL, SBCL, and
CLISP have TYPE-EXPAND functions in various packages.  You might
also consider shadowing DEFTYPE or scanning source files separately.
From: Pascal Bourguignon
Subject: Re: Expanding DEFTYPEs
Date: 
Message-ID: <87u0b41pol.fsf@thalassa.informatimago.com>
Kalle Olavi Niemitalo <···@iki.fi> writes:

> Florian Weimer <··@deneb.enyo.de> writes:
>
>> Is it possible to obtain the declaration of a DEFTYPE, based on the
>> name in that DEFTYPE?
>
> There is no standard way to do that by introspection after a
> COMMON-LISP:DEFTYPE form has been evaluated, but CMUCL, SBCL, and
> CLISP have TYPE-EXPAND functions in various packages.  You might
> also consider shadowing DEFTYPE or scanning source files separately.

Or rather:

(in-package :my-improved-cl)
(shadow 'deftype)
(defmacro deftype (&whole whole name args &body body)
   `(progn (cl:deftype ,name ,args ,@body)
           (setf (get ',name 'type-definition) ',whole)
           ',name))
(defun tdefinition (name) (get name 'type-definition))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

CAUTION: The mass of this product contains the energy equivalent of
85 million tons of TNT per net ounce of weight.