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

121 lines
7.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: Macro CHECK-TYPE</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_cerror.htm">
<LINK REL=UP HREF="c_condit.htm">
<LINK REL=NEXT HREF="e_smp_er.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_cerror.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_condit.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="e_smp_er.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="check-type"><I>Macro</I> <B>CHECK-TYPE</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>check-type</B> <I>place typespec [<I>string</I>]</I> =&gt; <I><A REL=DEFINITION HREF="a_nil.htm#nil"><B>nil</B></A></I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>place</I>---a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A>. <P>
<I>typespec</I>---a <A REL=DEFINITION HREF="26_glo_t.htm#type_specifier"><I>type specifier</I></A>. <P>
<I>string</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A>; evaluated. <P><B>Description:</B><P>
<P>
<A REL=DEFINITION HREF="#check-type"><B>check-type</B></A> signals a <A REL=DEFINITION HREF="26_glo_c.htm#correctable"><I>correctable</I></A> <A REL=DEFINITION HREF="26_glo_e.htm#error"><I>error</I></A> of <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A> <A REL=DEFINITION HREF="e_tp_err.htm#type-error"><B>type-error</B></A> if the contents of <I>place</I> are not of the type <I>typespec</I>. <P>
<A REL=DEFINITION HREF="#check-type"><B>check-type</B></A> can return only if the <A REL=DEFINITION HREF="a_store_.htm#store-value"><B>store-value</B></A> <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> is invoked, either explicitly from a handler or implicitly as one of the options offered by the debugger. If the <A REL=DEFINITION HREF="a_store_.htm#store-value"><B>store-value</B></A> <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> is invoked, <A REL=DEFINITION HREF="#check-type"><B>check-type</B></A> stores the new value that is the argument to the <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> invocation (or that is prompted for interactively by the debugger) in <I>place</I> and starts over, checking the type of the new value and signaling another error if it is still not of the desired <A REL=DEFINITION HREF="26_glo_t.htm#type"><I>type</I></A>. <P>
The first time <I>place</I> is <I>evaluated</I>, it is <I>evaluated</I> by normal evaluation rules. It is later <I>evaluated</I> as a <A REL=DEFINITION HREF="26_glo_p.htm#place"><I>place</I></A> if the type check fails and the <A REL=DEFINITION HREF="a_store_.htm#store-value"><B>store-value</B></A> <A REL=DEFINITION HREF="26_glo_r.htm#restart"><I>restart</I></A> is used; see <A REL=CHILD HREF="05_aaa.htm">Section 5.1.1.1 (Evaluation of Subforms to Places)</A>. <P>
<A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A> should be an English description of the type, starting with an indefinite article (``a'' or ``an''). If <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A> is not supplied, it is computed automatically from <I>typespec</I>. The automatically generated message mentions <I>place</I>, its contents, and the desired type. An implementation may choose to generate a somewhat differently worded error message if it recognizes that <I>place</I> is of a particular form, such as one of the arguments to the function that called <A REL=DEFINITION HREF="#check-type"><B>check-type</B></A>. <A REL=DEFINITION HREF="26_glo_s.htm#string"><I>string</I></A> is allowed because some applications of <A REL=DEFINITION HREF="#check-type"><B>check-type</B></A> may require a more specific description of what is wanted than can be generated automatically from <I>typespec</I>. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(setq aardvarks '(sam harry fred))
=&gt; (SAM HARRY FRED)
(check-type aardvarks (array * (3)))
&gt;&gt; Error: The value of AARDVARKS, (SAM HARRY FRED),
&gt;&gt; is not a 3-long array.
&gt;&gt; To continue, type :CONTINUE followed by an option number:
&gt;&gt; 1: Specify a value to use instead.
&gt;&gt; 2: Return to Lisp Toplevel.
&gt;&gt; Debug&gt; :CONTINUE 1
&gt;&gt; Use Value: #(SAM FRED HARRY)
=&gt; NIL
aardvarks
=&gt; #&lt;ARRAY-T-3 13571&gt;
(map 'list #'identity aardvarks)
=&gt; (SAM FRED HARRY)
(setq aardvark-count 'foo)
=&gt; FOO
(check-type aardvark-count (integer 0 *) &quot;A positive integer&quot;)
&gt;&gt; Error: The value of AARDVARK-COUNT, FOO, is not a positive integer.
&gt;&gt; To continue, type :CONTINUE followed by an option number:
&gt;&gt; 1: Specify a value to use instead.
&gt;&gt; 2: Top level.
&gt;&gt; Debug&gt; :CONTINUE 2
</PRE>
</TT> <P>
<PRE>
(defmacro define-adder (name amount)
(check-type name (and symbol (not null)) &quot;a name for an adder function&quot;)
(check-type amount integer)
`(defun ,name (x) (+ x ,amount)))
(macroexpand '(define-adder add3 3))
=&gt; (defun add3 (x) (+ x 3))
(macroexpand '(define-adder 7 7))
&gt;&gt; Error: The value of NAME, 7, is not a name for an adder function.
&gt;&gt; To continue, type :CONTINUE followed by an option number:
&gt;&gt; 1: Specify a value to use instead.
&gt;&gt; 2: Top level.
&gt;&gt; Debug&gt; :Continue 1
&gt;&gt; Specify a value to use instead.
&gt;&gt; Type a form to be evaluated and used instead: 'ADD7
=&gt; (defun add7 (x) (+ x 7))
(macroexpand '(define-adder add5 something))
&gt;&gt; Error: The value of AMOUNT, SOMETHING, is not an integer.
&gt;&gt; To continue, type :CONTINUE followed by an option number:
&gt;&gt; 1: Specify a value to use instead.
&gt;&gt; 2: Top level.
&gt;&gt; Debug&gt; :Continue 1
&gt;&gt; Type a form to be evaluated and used instead: 5
=&gt; (defun add5 (x) (+ x 5))
</PRE>
</TT> <P>
Control is transferred to a handler. <P>
<P><B>Side Effects:</B><P>
<P>
The debugger might be entered. <P>
<P><B>Affected By:</B><P>
<P>
<A REL=DEFINITION HREF="v_break_.htm#STbreak-on-signalsST"><B>*break-on-signals*</B></A> <P>
The implementation. <P>
<P><B>Exceptional Situations:</B> None.
<P>
<P><B>See Also:</B><P>
<P>
<A REL=CHILD HREF="09_a.htm">Section 9.1 (Condition System Concepts)</A> <P>
<P><B>Notes:</B><P>
<P>
<PRE>
(check-type place typespec)
== (assert (typep place 'typespec) (place)
'type-error :datum place :expected-type 'typespec)
</PRE>
</TT> <P>
<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>