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.
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
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
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.
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.