Common Lisp the Language 2nd Edition


next up previous contents index
Next: Determining the Type Up: Type Specifiers Previous: Defining New Type

4.8. Type Conversion Function

The following function may be used to convert an object to an equivalent object of another type.


[Function]
coerce object result-type

The result-type must be a type specifier; the object is converted to an ``equivalent'' object of the specified type. If the coercion cannot be performed then an error is signaled. In particular (coerce x 'nil) always signals an error. If object is already of the specified type as determined by typep then it is simply returned. It is not generally possible to convert any object to be of any type whatsoever; only certain conversions are permitted:

change_begin
X3J13 voted in June 1989 (SEQUENCE-TYPE-LENGTH)   to specify that coerce should signal an error if the new sequence type specifies the number of elements and the old sequence has a different length.

X3J13 voted in March 1989 (CHARACTER-PROPOSAL)   to specify that if the result-type is string then it is understood to mean (vector character) then it is understood to mean (vector character)tt>  es thepecify that/next_motif.gif">