1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/f_tp_of.htm
2024-04-01 10:24:07 +02:00

98 lines
8.9 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Function TYPE-OF</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="f_subtpp.htm">
<LINK REL=UP HREF="c_types_.htm">
<LINK REL=NEXT HREF="f_typep.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_subtpp.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_types_.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_typep.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="type-of"><I>Function</I> <B>TYPE-OF</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>type-of</B> <I>object</I> =&gt; <I>typespec</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>object</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
<I>typespec</I>---a <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>. <P>
<P><B>Description:</B><P>
<P>
<P>
Returns a <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>, <I>typespec</I>, for a <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> that has the <I>object</I> as an <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>element</I></A>. The <I>typespec</I> satisfies the following: <P>
<P><DL><P>
<DT>1. For any <I>object</I> that is an <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>element</I></A> of some <A REL=DEFINITION HREF="26_glo_b.htm#built-in_type"><I>built-in type</I></A>: <P><DD>
<P><DL><DT>a. the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> returned is a <A REL=DEFINITION HREF="26_glo_r.htm#recognizable_subtype"><I>recognizable subtype</I></A> of that <A REL=DEFINITION HREF="26_glo_b.htm#built-in_type"><I>built-in type</I></A>. <P><DD>
<DT>b. the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> returned does not involve <TT>and</TT>, <TT>eql</TT>, <TT>member</TT>, <TT>not</TT>, <TT>or</TT>, <TT>satisfies</TT>, or <TT>values</TT>. <P><DD></DL><P>
<DT>2. For all <I>objects</I>, <TT>(typep </TT><I>object</I><TT> (type-of </TT><I>object</I><TT>))</TT> returns <A REL=DEFINITION HREF="26_glo_t.htm#true"><I>true</I></A>. Implicit in this is that <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifiers</I></A> which are not valid for use with <A REL=DEFINITION HREF="f_typep.htm#typep"><B>typep</B></A>, such as the <A REL=DEFINITION HREF="26_glo_l.htm#list"><I>list</I></A> form of the <A REL=DEFINITION HREF="s_fn.htm#function"><B>function</B></A> <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>, are never returned by <A REL=DEFINITION HREF="#type-of"><B>type-of</B></A>. <P><DD>
<DT>3. The <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> returned by <A REL=DEFINITION HREF="#type-of"><B>type-of</B></A> is always a <A REL=DEFINITION HREF="26_glo_r.htm#recognizable_subtype"><I>recognizable subtype</I></A> of the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> returned by <A REL=DEFINITION HREF="f_clas_1.htm#class-of"><B>class-of</B></A>. That is, <P><DD>
<PRE>
(subtypep (type-of object) (class-of object)) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>, <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
</PRE>
</TT> <P>
<DT>4. For <I>objects</I> of metaclass <A REL=DEFINITION HREF="t_stu_cl.htm#structure-class"><B>structure-class</B></A> or <A REL=DEFINITION HREF="t_std_cl.htm#standard-class"><B>standard-class</B></A>, and for <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A>, <A REL=DEFINITION HREF="#type-of"><B>type-of</B></A> returns the <A REL=DEFINITION HREF="26_glo_p.htm#proper_name"><I>proper name</I></A> of the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> returned by <A REL=DEFINITION HREF="f_clas_1.htm#class-of"><B>class-of</B></A> if it has a <A REL=DEFINITION HREF="26_glo_p.htm#proper_name"><I>proper name</I></A>, and otherwise returns the <A REL=DEFINITION HREF="26_glo_c.htm#class"><I>class</I></A> itself. In particular, for <I>objects</I> created by the constructor function of a structure defined with <A REL=DEFINITION HREF="m_defstr.htm#defstruct"><B>defstruct</B></A> without a <TT>:type</TT> option, <A REL=DEFINITION HREF="#type-of"><B>type-of</B></A> returns the structure name; and for <I>objects</I> created by <A REL=DEFINITION HREF="f_mk_cnd.htm#make-condition"><B>make-condition</B></A>, the <I>typespec</I> is the <A REL=DEFINITION HREF="26_glo_n.htm#name"><I>name</I></A> of the <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>condition</I></A> <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>. <P><DD>
<DT>5. For each of the <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>types</I></A> <A REL=DEFINITION HREF="t_short_.htm#short-float"><B>short-float</B></A>, <A REL=DEFINITION HREF="t_short_.htm#single-float"><B>single-float</B></A>, <A REL=DEFINITION HREF="t_short_.htm#double-float"><B>double-float</B></A>, or <A REL=DEFINITION HREF="t_short_.htm#long-float"><B>long-float</B></A> of which the <I>object</I> is an <A REL=DEFINITION HREF="26_glo_e.htm#element"><I>element</I></A>, the <I>typespec</I> is a <A REL=DEFINITION HREF="26_glo_r.htm#recognizable_subtype"><I>recognizable subtype</I></A> of that <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>. <P><DD>
<P></DL><P>
<P>
<P><B>Examples:</B><P>
<P>
<PRE>
</PRE>
</TT> <P>
<PRE>
(type-of 'a) =&gt; SYMBOL
(type-of '(1 . 2))
=&gt; CONS
OR=&gt; (CONS FIXNUM FIXNUM)
(type-of #c(0 1))
=&gt; COMPLEX
OR=&gt; (COMPLEX INTEGER)
(defstruct temp-struct x y z) =&gt; TEMP-STRUCT
(type-of (make-temp-struct)) =&gt; TEMP-STRUCT
(type-of &quot;abc&quot;)
=&gt; STRING
OR=&gt; (STRING 3)
(subtypep (type-of &quot;abc&quot;) 'string) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>, <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(type-of (expt 2 40))
=&gt; BIGNUM
OR=&gt; INTEGER
OR=&gt; (INTEGER 1099511627776 1099511627776)
OR=&gt; SYSTEM::TWO-WORD-BIGNUM
OR=&gt; FIXNUM
(subtypep (type-of 112312) 'integer) =&gt; <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>, <A REL=DEFINITION HREF="26_glo_t.htm#true">true</A>
(defvar *foo* (make-array 5 :element-type t)) =&gt; *FOO*
(class-name (class-of *foo*)) =&gt; VECTOR
(type-of *foo*)
=&gt; VECTOR
OR=&gt; (VECTOR T 5)
</PRE>
</TT> <P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B> None.
<P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="f_ar_ele.htm#array-element-type"><B>array-element-type</B></A>, <A REL=DEFINITION HREF="f_clas_1.htm#class-of"><B>class-of</B></A>, <A REL=DEFINITION HREF="m_defstr.htm#defstruct"><B>defstruct</B></A>, <A REL=DEFINITION HREF="m_tpcase.htm#typecase"><B>typecase</B></A>, <A REL=DEFINITION HREF="f_typep.htm#typep"><B>typep</B></A>, <A REL=CHILD HREF="04_b.htm">Section 4.2 (Types)</A> <P>
<P><B>Notes:</B><P>
<P>
Implementors are encouraged to arrange for <A REL=DEFINITION HREF="#type-of"><B>type-of</B></A> to return a portable value. <P>
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss350.htm">TYPE-OF-AND-PREDEFINED-CLASSES:TYPE-OF-HANDLES-FLOATS</A><LI> <A REL=CHILD HREF="../Issues/iss351.htm">TYPE-OF-AND-PREDEFINED-CLASSES:UNIFY-AND-EXTEND</A><LI> <A REL=CHILD HREF="../Issues/iss352.htm">TYPE-OF-UNDERCONSTRAINED:ADD-CONSTRAINTS</A><P></UL><HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>