File: assert.html

package info (click to toggle)
gcl 2.6.14-21
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 60,864 kB
  • sloc: ansic: 177,407; lisp: 151,509; asm: 128,169; sh: 22,510; cpp: 11,923; tcl: 3,181; perl: 2,930; makefile: 2,360; sed: 334; yacc: 226; lex: 95; awk: 30; fortran: 24; csh: 23
file content (173 lines) | stat: -rw-r--r-- 7,781 bytes parent folder | download | duplicates (4)
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
<!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>assert (ANSI and GNU Common Lisp Document)</title>

<meta name="description" content="assert (ANSI and GNU Common Lisp Document)">
<meta name="keywords" content="assert (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="error.html" rel="next" title="error">
<link href="storage_002dcondition.html" rel="prev" title="storage-condition">
<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="assert"></span><div class="header">
<p>
Next: <a href="error.html" accesskey="n" rel="next">error</a>, Previous: <a href="storage_002dcondition.html" accesskey="p" rel="prev">storage-condition</a>, Up: <a href="Conditions-Dictionary.html" accesskey="u" rel="up">Conditions Dictionary</a> &nbsp; </p>
</div>
<hr>
<span id="assert-_005bMacro_005d"></span><h4 class="subsection">9.2.10 assert                                                              [Macro]</h4>

<p><code>assert</code>  <i>test-form <span class="roman">[</span><span class="roman">(</span>{<i>place</i>}*<span class="roman">)</span>
                                          <span class="roman">[</span>datum-form
                                                {<i>argument-form</i>}*<span class="roman">]</span><span class="roman">]</span></i><br>
   &rArr;  <i><b>nil</b></i>
</p>
<span id="Arguments-and-Values_003a_003a-132"></span><h4 class="subsubheading">Arguments and Values::</h4>

<p><i>test-form</i>&mdash;a <i>form</i>; always evaluated.
</p>
<p><i>place</i>&mdash;a <i>place</i>; evaluated if an error is signaled.
</p>
<p><i>datum-form</i>&mdash;a <i>form</i> that evaluates to a <i>datum</i>.
  Evaluated each time an error is to be signaled, 
  or not at all if no error is to be signaled.
</p>
<p><i>argument-form</i>&mdash;a <i>form</i> that evaluates to an <i>argument</i>.
  Evaluated each time an error is to be signaled, 
  or not at all if no error is to be signaled.
</p>
<p><i>datum</i>, <i>arguments</i>&mdash;<i>designators</i> for a <i>condition</i> 
 of default type <b>error</b>.  (These <i>designators</i> are the
 result of evaluating <i>datum-form</i> and each of the <i>argument-forms</i>.)
</p>
<span id="Description_003a_003a-180"></span><h4 class="subsubheading">Description::</h4>

<p><b>assert</b> assures that <i>test-form</i> evaluates to <i>true</i>.
If <i>test-form</i> evaluates to <i>false</i>, <b>assert</b> signals a
<i>correctable</i> <i>error</i> (denoted by <i>datum</i> and <i>arguments</i>).
Continuing from this error using the <b>continue</b> <i>restart</i> makes it possible
for the user to alter the values of the <i>places</i> before
<b>assert</b> evaluates <i>test-form</i> again.
If the value of <i>test-form</i> is <i>non-nil</i>,
<b>assert</b> returns <b>nil</b>.
</p>
<p>The <i>places</i> are <i>generalized references</i> to data
upon which <i>test-form</i> depends, 
whose values can be changed by the user in attempting to correct the error.
<i>Subforms</i> of each <i>place</i> are only evaluated if an error is signaled, 
and might be re-evaluated if the error is re-signaled (after continuing without
actually fixing the problem).
</p>
<p>The order of evaluation of the <i>places</i> is not specified;
see <a href="Evaluation-of-Subforms-to-Places.html">Evaluation of Subforms to Places</a>.
<span id="index-order-of-evaluation-8"></span>
</p>
<span id="index-evaluation-order-8"></span>

<p>If a <i>place</i> <i>form</i> is supplied that produces more values than there
are store variables, the extra values are ignored. If the supplied 
<i>form</i> produces fewer values than there are store variables, 
the missing values are set to <b>nil</b>.
</p>
<span id="Examples_003a_003a-114"></span><h4 class="subsubheading">Examples::</h4>
<div class="example">
<pre class="example"> (setq x (make-array '(3 5) :initial-element 3))
&rArr;  #2A((3 3 3 3 3) (3 3 3 3 3) (3 3 3 3 3))
 (setq y (make-array '(3 5) :initial-element 7))
&rArr;  #2A((7 7 7 7 7) (7 7 7 7 7) (7 7 7 7 7))
 (defun matrix-multiply (a b)
   (let ((*print-array* nil))
     (assert (and (= (array-rank a) (array-rank b) 2)
                  (= (array-dimension a 1) (array-dimension b 0)))
             (a b)
             &quot;Cannot multiply ~S by ~S.&quot; a b)
            (really-matrix-multiply a b))) &rArr;  MATRIX-MULTIPLY
 (matrix-multiply x y)
<tt> |&gt; </tt> Correctable error in MATRIX-MULTIPLY: 
<tt> |&gt; </tt> Cannot multiply #&lt;ARRAY ...&gt; by #&lt;ARRAY ...&gt;.
<tt> |&gt; </tt> Restart options:
<tt> |&gt; </tt>  1: You will be prompted for one or more new values.
<tt> |&gt; </tt>  2: Top level.
<tt> |&gt; </tt> Debug&gt; <b>|&gt;&gt;</b><tt>:continue 1</tt><b>&lt;&lt;|</b>
<tt> |&gt; </tt> Value for A: <b>|&gt;&gt;</b><tt>x</tt><b>&lt;&lt;|</b>
<tt> |&gt; </tt> Value for B: <b>|&gt;&gt;</b><tt>(make-array '(5 3) :initial-element 6)</tt><b>&lt;&lt;|</b>
&rArr;  #2A((54 54 54 54 54)
       (54 54 54 54 54)
       (54 54 54 54 54)
       (54 54 54 54 54)
       (54 54 54 54 54))
</pre></div>

<div class="example">
<pre class="example"> (defun double-safely (x) (assert (numberp x) (x)) (+ x x))
 (double-safely 4) 
&rArr;  8

 (double-safely t)
<tt> |&gt; </tt> Correctable error in DOUBLE-SAFELY: The value of (NUMBERP X) must be non-NIL.
<tt> |&gt; </tt> Restart options:
<tt> |&gt; </tt>  1: You will be prompted for one or more new values.
<tt> |&gt; </tt>  2: Top level.
<tt> |&gt; </tt> Debug&gt; <b>|&gt;&gt;</b><tt>:continue 1</tt><b>&lt;&lt;|</b>
<tt> |&gt; </tt> Value for X: <b>|&gt;&gt;</b><tt>7</tt><b>&lt;&lt;|</b>
&rArr;  14
</pre></div>

<span id="Affected-By_003a_003a-18"></span><h4 class="subsubheading">Affected By::</h4>

<p><b>*break-on-signals*</b>
</p>
<p>The set of active <i>condition handlers</i>.
</p>
<span id="See-Also_003a_003a-158"></span><h4 class="subsubheading">See Also::</h4>

<p><a href="check_002dtype.html">check-type</a>
, 
<a href="error.html">error</a>
, <a href="Generalized-Reference.html">Generalized Reference</a>
</p>
<span id="Notes_003a_003a-97"></span><h4 class="subsubheading">Notes::</h4>

<p>The debugger need not include the <i>test-form</i> in the error message,
and the <i>places</i> should not be included in the message, but they
should be made available for the user&rsquo;s perusal.  If the user gives the
&ldquo;continue&rdquo; command, the values of any of the references can be altered.
The details of this depend on the implementation&rsquo;s style of user interface.
</p>
<hr>
<div class="header">
<p>
Next: <a href="error.html" accesskey="n" rel="next">error</a>, Previous: <a href="storage_002dcondition.html" accesskey="p" rel="prev">storage-condition</a>, Up: <a href="Conditions-Dictionary.html" accesskey="u" rel="up">Conditions Dictionary</a> &nbsp; </p>
</div>



</body>
</html>