Common Lisp the Language, 2nd Edition


next up previous contents index
Next: Type Upgrading Up: Type Specifiers Previous: Type Conversion Function

4.9. Determining the Type of an Object

The following function may be used to obtain a type specifier describing the type of a given object.


[Function]
type-of object

old_change_begin
(type-of object) returns an implementation-dependent result: some type of which the object is a member. Implementors are encouraged to arrange for type-of to return the most specific type that can be conveniently computed and is likely to be useful to the user. If the argument is a user-defined named structure created by defstruct, then type-of will return the type name of that structure. Because the result is implementation-dependent, it is usually better to use type-of primarily for debugging purposes; however, in a few situations portable code requires the use of type-of, such as when the result is to be given to the coerce or map function. On the other hand, often the typep function or the typecase construct is more appropriate than type-of.
old_change_end


Compatibility note: In MacLisp the function type-of is called typep, and anomalously so, for it is not a predicate.

change_begin
Many have observed (and rightly so) that this specification is totally wimpy and therefore nearly useless. X3J13 voted in June 1989 (TYPE-OF-UNDERCONSTRAINED)   to place the following constraints on type-of:

As an example, (type-of "acetylcholinesterase") may return string or simple-string or (simple-string 20), but not array or simple-vector. As another example, it is permitted for (type-of 1729) to return integer or fixnum (if it is indeed a fixnum) or (signed-byte 16) or (integer 1729 1729) or (integer 1685 1750) or even (mod 1730), but not rational or number, because

(typep (+ (expt 9 3) (expt 10 3)) 'integer)

is true, integer is in the list of types mentioned above, and

(subtypep (type-of (+ (expt 1 3) (expt 12 3))) 'integer)

would be false if type-of were to return rational or number.
change_end



next up previous contents index
Next: Type Upgrading Up: Type Specifiers Previous: Type Conversion Function


AI[email protected]