1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>check-type (ANSI and GNU Common Lisp Document)</title>
<meta name="description" content="check-type (ANSI and GNU Common Lisp Document)">
<meta name="keywords" content="check-type (ANSI and GNU Common Lisp Document)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Conditions-Dictionary.html" rel="up" title="Conditions Dictionary">
<link href="simple_002derror.html" rel="next" title="simple-error">
<link href="cerror.html" rel="prev" title="cerror">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<span id="check_002dtype"></span><div class="header">
<p>
Next: <a href="simple_002derror.html" accesskey="n" rel="next">simple-error</a>, Previous: <a href="cerror.html" accesskey="p" rel="prev">cerror</a>, Up: <a href="Conditions-Dictionary.html" accesskey="u" rel="up">Conditions Dictionary</a> </p>
</div>
<hr>
<span id="check_002dtype-_005bMacro_005d"></span><h4 class="subsection">9.2.13 check-type [Macro]</h4>
<p><code>check-type</code> <i>place typespec <span class="roman"><span class="roman">[</span><i>string</i><span class="roman">]</span></span></i> ⇒ <i><b>nil</b></i>
</p>
<span id="Arguments-and-Values_003a_003a-135"></span><h4 class="subsubheading">Arguments and Values::</h4>
<p><i>place</i>—a <i>place</i>.
</p>
<p><i>typespec</i>—a <i>type specifier</i>.
</p>
<p><i>string</i>—a <i>string</i>; evaluated.
</p>
<span id="Description_003a_003a-183"></span><h4 class="subsubheading">Description::</h4>
<p><b>check-type</b> signals a <i>correctable</i> <i>error</i>
of <i>type</i> <b>type-error</b> if the contents of <i>place</i> are not
of the type <i>typespec</i>.
</p>
<p><b>check-type</b> can return only if the <b>store-value</b> <i>restart</i> is invoked,
either explicitly from a handler
or implicitly as one of the options offered by the debugger.
If the <b>store-value</b> <i>restart</i> is invoked,
<b>check-type</b> stores the new value
that is the argument to the <i>restart</i> 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 <i>type</i>.
</p>
<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 <i>place</i>
if the type check fails and the <b>store-value</b> <i>restart</i> is used;
see <a href="Evaluation-of-Subforms-to-Places.html">Evaluation of Subforms to Places</a>.
</p>
<p><i>string</i> should be an English description of the type,
starting with an indefinite article (“a” or “an”).
If <i>string</i> 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 <b>check-type</b>.
<i>string</i> is allowed because some applications of <b>check-type</b>
may require a more specific description of what is wanted
than can be generated automatically from <i>typespec</i>.
</p>
<span id="Examples_003a_003a-117"></span><h4 class="subsubheading">Examples::</h4>
<div class="example">
<pre class="example"> (setq aardvarks '(sam harry fred))
⇒ (SAM HARRY FRED)
(check-type aardvarks (array * (3)))
<tt> |> </tt> Error: The value of AARDVARKS, (SAM HARRY FRED),
<tt> |> </tt> is not a 3-long array.
<tt> |> </tt> To continue, type :CONTINUE followed by an option number:
<tt> |> </tt> 1: Specify a value to use instead.
<tt> |> </tt> 2: Return to Lisp Toplevel.
<tt> |> </tt> Debug> <b>|>></b><tt>:CONTINUE 1</tt><b><<|</b>
<tt> |> </tt> Use Value: <b>|>></b><tt>#(SAM FRED HARRY)</tt><b><<|</b>
⇒ NIL
aardvarks
⇒ #<ARRAY-T-3 13571>
(map 'list #'identity aardvarks)
⇒ (SAM FRED HARRY)
(setq aardvark-count 'foo)
⇒ FOO
(check-type aardvark-count (integer 0 *) "A positive integer")
<tt> |> </tt> Error: The value of AARDVARK-COUNT, FOO, is not a positive integer.
<tt> |> </tt> To continue, type :CONTINUE followed by an option number:
<tt> |> </tt> 1: Specify a value to use instead.
<tt> |> </tt> 2: Top level.
<tt> |> </tt> Debug> <b>|>></b><tt>:CONTINUE 2</tt><b><<|</b>
</pre></div>
<div class="example">
<pre class="example"> (defmacro define-adder (name amount)
(check-type name (and symbol (not null)) "a name for an adder function")
(check-type amount integer)
`(defun ,name (x) (+ x ,amount)))
(macroexpand '(define-adder add3 3))
⇒ (defun add3 (x) (+ x 3))
(macroexpand '(define-adder 7 7))
<tt> |> </tt> Error: The value of NAME, 7, is not a name for an adder function.
<tt> |> </tt> To continue, type :CONTINUE followed by an option number:
<tt> |> </tt> 1: Specify a value to use instead.
<tt> |> </tt> 2: Top level.
<tt> |> </tt> Debug> <b>|>></b><tt>:Continue 1</tt><b><<|</b>
<tt> |> </tt> Specify a value to use instead.
<tt> |> </tt> Type a form to be evaluated and used instead: <b>|>></b><tt>'ADD7</tt><b><<|</b>
⇒ (defun add7 (x) (+ x 7))
(macroexpand '(define-adder add5 something))
<tt> |> </tt> Error: The value of AMOUNT, SOMETHING, is not an integer.
<tt> |> </tt> To continue, type :CONTINUE followed by an option number:
<tt> |> </tt> 1: Specify a value to use instead.
<tt> |> </tt> 2: Top level.
<tt> |> </tt> Debug> <b>|>></b><tt>:Continue 1</tt><b><<|</b>
<tt> |> </tt> Type a form to be evaluated and used instead: <b>|>></b><tt>5</tt><b><<|</b>
⇒ (defun add5 (x) (+ x 5))
</pre></div>
<p>Control is transferred to a handler.
</p>
<span id="Side-Effects_003a_003a-9"></span><h4 class="subsubheading">Side Effects::</h4>
<p>The debugger might be entered.
</p>
<span id="Affected-By_003a_003a-21"></span><h4 class="subsubheading">Affected By::</h4>
<p><b>*break-on-signals*</b>
</p>
<p>The implementation.
</p>
<span id="See-Also_003a_003a-161"></span><h4 class="subsubheading">See Also::</h4>
<p><a href="Condition-System-Concepts.html">Condition System Concepts</a>
</p>
<span id="Notes_003a_003a-100"></span><h4 class="subsubheading">Notes::</h4>
<div class="example">
<pre class="example"> (check-type <i>place</i> <i>typespec</i>)
≡ (assert (typep <i>place</i> '<i>typespec</i>) (<i>place</i>)
'type-error :datum <i>place</i> :expected-type '<i>typespec</i>)
</pre></div>
<hr>
<div class="header">
<p>
Next: <a href="simple_002derror.html" accesskey="n" rel="next">simple-error</a>, Previous: <a href="cerror.html" accesskey="p" rel="prev">cerror</a>, Up: <a href="Conditions-Dictionary.html" accesskey="u" rel="up">Conditions Dictionary</a> </p>
</div>
</body>
</html>
|