Why can't I say the following?
(deftype boolean ()
(member nil t))
In CMUCL 18d I get the following cryptic (as usual) warning:
In: DEFTYPE BOOLEAN
T
Warning: This is not a (VALUES &OPTIONAL LIST &REST T):
T
Is what I'm doing wrong? Or is CMUCL just being weird? I stared at
the CLHS entry for DEFTYPE for a while and couldn't see anything
obviously wrong with (member nil t).
The point is I want to restrict values to only T and NIL. Nothing
else. I could do this in every place I want only these values by
explicitly checking for (eq t) and (eq nil) but I'd rather put the
burden on the type checker.
'james
--
James A. Crippen <·····@unlambda.com> ,-./-. Anchorage, Alaska,
Lambda Unlimited: Recursion 'R' Us | |/ | USA, 61.20939N, -149.767W
Y = \f.(\x.f(xx)) (\x.f(xx)) | |\ | Earth, Sol System,
Y(F) = F(Y(F)) \_,-_/ Milky Way.
·····@unlambda.com (James A. Crippen) writes:
> Why can't I say the following?
>
> (deftype boolean ()
> (member nil t))
>
> In CMUCL 18d I get the following cryptic (as usual) warning:
>
> In: DEFTYPE BOOLEAN
> T
> Warning: This is not a (VALUES &OPTIONAL LIST &REST T):
> T
You want:
(deftype boolean ()
'(member nil t))
The body of a DEFTYPE is evaluated as an implicit progn and returns a
type specifier. So in your example, CMUCL is quite rightly trying to
_execute_ the call to MEMBER, and failing because T isn't a
list. Amusingly, if you write it the other way round:
(deftype boolean ()
(member t nil))
Then, since the call to member returns NIL, your new BOOLEAN type will
be the empty type. :-)
Christophe
--
Jesus College, Cambridge, CB5 8BL +44 1223 510 299
http://www-jcsu.jesus.cam.ac.uk/~csr21/ (defun pling-dollar
(str schar arg) (first (last +))) (make-dispatch-macro-character #\! t)
(set-dispatch-macro-character #\! #\$ #'pling-dollar)
Christophe Rhodes <·····@cam.ac.uk> writes:
> ·····@unlambda.com (James A. Crippen) writes:
>
> > Why can't I say the following?
> >
> > (deftype boolean ()
> > (member nil t))
> >
> > In CMUCL 18d I get the following cryptic (as usual) warning:
> >
> > In: DEFTYPE BOOLEAN
> > T
> > Warning: This is not a (VALUES &OPTIONAL LIST &REST T):
> > T
>
> You want:
>
> (deftype boolean ()
> '(member nil t))
I just figured that out. That's what I get for asking too soon.
'james
--
James A. Crippen <·····@unlambda.com> ,-./-. Anchorage, Alaska,
Lambda Unlimited: Recursion 'R' Us | |/ | USA, 61.20939N, -149.767W
Y = \f.(\x.f(xx)) (\x.f(xx)) | |\ | Earth, Sol System,
Y(F) = F(Y(F)) \_,-_/ Milky Way.
·····@unlambda.com (James A. Crippen) writes:
> Why can't I say the following?
>
> (deftype boolean ()
> (member nil t))
Also, are you aware that the boolean type is built into Common Lisp?
--
Frode Vatvedt Fjeld
Frode Vatvedt Fjeld <······@acm.org> writes:
> ·····@unlambda.com (James A. Crippen) writes:
>
> > Why can't I say the following?
> >
> > (deftype boolean ()
> > (member nil t))
>
> Also, are you aware that the boolean type is built into Common Lisp?
I am now. I must have missed it when looking. I don't usually worry
about types much...
'james
--
James A. Crippen <·····@unlambda.com> ,-./-. Anchorage, Alaska,
Lambda Unlimited: Recursion 'R' Us | |/ | USA, 61.20939N, -149.767W
Y = \f.(\x.f(xx)) (\x.f(xx)) | |\ | Earth, Sol System,
Y(F) = F(Y(F)) \_,-_/ Milky Way.