[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: type-of



Two comments on your comments.

First of all, neither TYPE-OF or SUBTYPEP is necessary for implementing
TYPEP.  In fact, doing it that way is probably the most inefficient 
implementation possible.  In PCLS, for example, all of the built-in types
like INTEGER or SIMPLE-STRING have predicates associated with them that
can be found by a quick lookup procedure, and there is special logic for 
handling the more complicated type specifiers like (ARRAY ...).

I agree that TYPE-OF should not be thrown out just because nobody uses
it much, *provided* that the function is there because it implements some
functionality users could not easily implement themselves.  For the uses
of TYPE-OF that people have mentioned so far, this is not the case.  Here
is a portable, 3-line function that will check an object against whatever
set of type specifiers I think are appropriate in this situation:

(defun my-type-of (object possible-type-spec-list)
    (dolist (type possible-type-spec-list t)
        (if (typep object type) (return type))))

The only case where this would fail would be if I do not know in advance
what type specifiers I want to see returned.  Gee whiz!  Isn't that what
TYPE-OF is supposed to do now?  :-)

-Sandra
-------