Re: Find if the symbol is a type
Nick Levine <nick@nicklevine.org> writes:
> I've been thinking about (subtype thing t) vs (subtype nil thing). The
> tests are equivalent, right? But there's something more expressive
> about the second one, that I can't quite lay a finger on.
You're feeling there's something more expressive about the second
one, because you've got the impression that there could still be
something outside of the totallity. Nope. as types, T and NIL are
perfect complements, and there's nothing outside of them (and since
there's nothing inside NIL, there's nothing outside of T). By
definition.
As for them to be equivalent, in the abstract way, of course; but I
could imagine an implementation giving different results. Happily, sbcl
is consistent there, but given that it assumes any unknown symbol is a
type, I would not have been surprised if it had returned T for (subtypep
'foo 't) but NIL for (subtypep 'nil 'foo).
Ie. in (subtypep u k), the unknown is u (what you are usually testing),
while the known is k and is expected to be a type. Which makes me feel
(subtypep a-type 't) safer than (subtypep 'nil a-type).
But the specification eventually resolves on the term "membership" in
this glossary entry:
subtype n. a type whose membership is the same as or a proper
subset of the membership of another type, called a
supertype. (Every type is a subtype of itself.)
and it's not defined, therefore we can take it to mean the usual
mathematical membership, and it can be read both ways.
A ⊆ B ⇔ B ⊇ A
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html