Debian Codegraph @

docsrc/xlisp/xlisp-doc/manual/xlisp.htm

raw
1 <html><head>
2
3 <title>XLISP 2.0</title>
4
5 <style type="text/css">
6 .example {
7 color: #000000;
8 background-color: #F5F5F5;
9 padding: 8px;
10 border: #the-readtable08080;
11 border-style: solid;
12 border-width: 1px;
13 width:auto;
14 }
15 .button {
16 color: #000000;
17 background-color: #F5F5F5;
18 padding-top: 1px;
19 padding-bottom: 1px;
20 padding-left: 4px;
21 padding-right: 8px;
22 border: #the-readtable08080;
23 border-style: solid;
24 border-width: 1px;
25 white-space: pre;
26 }
27 .box {
28 color: #000000;
29 padding-top: 4px;
30 padding-bottom: 4px;
31 padding-left: 16px;
32 padding-right: 16px;
33 border: #the-readtable08080;
34 border-style: solid;
35 border-width: 1px;
36 }
37 </style>
38
39 </head>
40
41 <body>
42
43 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
44 <a href="contents.htm">Contents</a> |
45 <a href="../tutorials/tutorials.htm">Tutorials</a> |
46 <a href="../examples/examples.htm">Examples</a> |
47 <a href="../reference/reference-index.htm">Reference</a>
48
49 <hr>
50
51 <h1>XLISP 2.0</h1>
52
53 <hr>
54
55 <p><nobr><b>XLISP: An Object-oriented Lisp</b>&nbsp;</nobr> <nobr>Version
56 2.0</nobr>, <nobr>February 6, 1988</nobr>, by <nobr>David Michael
57 Betz</nobr>, <nobr>127 Taylor Road</nobr>, Peterborough, <nobr>NH
58 03458</nobr></p>
59
60 <p><nobr>Copyright (c) 1988</nobr>, by <nobr>David Michael Betz</nobr>,
61 <nobr>All Rights Reserved</nobr>, Permission is granted for unrestricted
62 <nobr>non-commercial use</nobr>.</p>
63
64 <hr>
65
66 <ol>
67 <li><nobr><a href="#introduction">Introduction</a></nobr></li>
68 <li><nobr><a href="#a-note-from-the-author">A Note From The Author</a></nobr></li>
69 <li><nobr><a href="#command-loop">Command Loop</a></nobr></li>
70 <li><nobr><a href="#break-loop">Break Loop</a></nobr></li>
71 <li><nobr><a href="#data-types">Data Types</a></nobr></li>
72 <li><nobr><a href="#the-evaluator">The Evaluator</a></nobr></li>
73 <li><nobr><a href="#lexical-conventions">Lexical Conventions</a></nobr></li>
74 <li><nobr><a href="#the-readtable">The Readtable</a></nobr></li>
75 <li><nobr><a href="#lambda-lists">Lambda Lists</a></nobr></li>
76 <ul>
77 <li><nobr><a href="#arguments">Arguments</a></nobr></li>
78 <ul>
79 <li><nobr><a href="#required-arguments">Required Arguments</a></nobr></li>
80 <li><nobr><a href="#optional-arguments">Optional Arguments</a></nobr></li>
81 <li><nobr><a href="#rest-argument">Rest Argument</a></nobr></li>
82 <li><nobr><a href="#keyword-arguments">Keyword Arguments</a></nobr></li>
83 <li><nobr><a href="#auxiliary-variables">Auxiliary Variables</a></nobr></li>
84 </ul>
85 <li><nobr><a href="#lambda-list-syntax">Lambda List Syntax</a></nobr></li>
86 </ul>
87 </ol>
88
89 <a name="introduction"></a>
90
91 <hr>
92
93 <h2>1&nbsp; Introduction</h2>
94
95 <hr>
96
97 <p>XLISP is an experimental programming language combining some of the
98 features of Common Lisp with an object-oriented extension capability. It was
99 implemented to allow experimentation with object-oriented programming on
100 small computers. Implementations of XLISP run on virtually every operating
101 system. XLISP is completely written in the programming language C and is
102 easily extended with user written built-in functions and classes. It is
103 available in source form to non-commercial users. Many Common Lisp functions
104 are built into XLISP. In addition, XLISP defines the objects <a
105 href="../reference/object.htm">object</a> and <a
106 href="../reference/class.htm">class</a> as primitives. Object is the
107 only class that has no superclass and hence is the root of the class
108 hierarchy tree. Class is the class of which all classes are instances [it is
109 the only object that is an instance of itself].</p>
110
111 <p>This document is a brief description of XLISP. It assumes some knowledge
112 of LISP and some understanding of the concepts of object-oriented
113 programming. I recommend the book 'Lisp' by Winston and Horn and published
114 by Addison Wesley for learning Lisp. The first edition of this book is based
115 on MacLisp and the second edition is based on Common Lisp. You will probably
116 also need a copy of 'Common Lisp, The Language' by Guy L. Steele, Jr.,
117 published by Digital Press to use as a reference for some of the Common Lisp
118 functions that are described only briefly in this document.</p>
119
120 <p>A list with Lisp books and documents available for free in the internet
121 can be found under <a href="../misc/links.htm">Lisp Links</a>.</p>
122
123 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to Top</a></nobr></p>
124
125 <a name="a-note-from-the-author"></a>
126
127 <hr>
128
129 <h2>2&nbsp; A Note From The Author</h2>
130
131 <hr>
132
133 <p>If you have any problems with XLISP, feel free to contact me [David Betz]
134 for help or advice. Please remember that since XLISP is available in source
135 form in a high level language, many users have been making versions
136 available on a variety of machines. If you call to report a problem with a
137 specific version, I may not be able to help you if that version runs on a
138 machine to which I don't have access. Please have the version number of the
139 version that you are running readily accessible before calling me.</p>
140
141 <p>If you find a bug in XLISP, first try to fix the bug yourself using the
142 source code provided. If you are successful in fixing the bug, send the bug
143 report along with the fix to me. If you don't have access to a C compiler or
144 are unable to fix a bug, please send the bug report to me and I'll try to
145 fix it.</p>
146
147 <p>Any suggestions for improvements will be welcomed. Feel free to extend
148 the language in whatever way suits your needs. However,</p>
149
150 <p><div class="box">
151
152 <p><b>PLEASE DO NOT RELEASE ENHANCED VERSIONS WITHOUT CHECKING WITH ME
153 FIRST!!</b></p>
154
155 </div></p>
156
157 <p>I would like to be the clearing house for new features added to XLISP. If
158 you want to add features for your own personal use, go ahead. But, if you
159 want to distribute your enhanced version, contact me first. Please remember
160 that the goal of XLISP is to provide a language to learn and experiment with
161 LISP and object-oriented programming on small computers. I don't want it to
162 get so big that it requires megabytes of memory to run.</p>
163
164 <p>The official XLISP homepage is:</p>
165
166 <ul>
167 <li><a href="http://www.mv.com/ipusers/xlisper/">http://www.mv.com/ipusers/xlisper/</a></li>
168 </ul>
169
170 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
171
172 <a name="command-loop"></a>
173
174 <hr>
175
176 <h2>3&nbsp; Command Loop</h2>
177
178 <hr>
179
180 <p>When XLISP is started, it first tries to load the workspace 'xlisp.wks'
181 from the current directory. If that file doesn't exist, XLISP builds an
182 initial workspace, empty except for the built-in functions and symbols. Then
183 XLISP attempts to load 'init.lsp' from the current directory. It then loads
184 any files named as parameters on the command line [after appending '.lsp' to
185 their names].</p>
186
187 <p>XLISP then issues the following prompt:</p>
188
189 <pre class="example">
190 &gt;
191 </pre>
192
193 <p>This indicates that XLISP is waiting for an expression to be typed. When
194 a complete expression has been entered, XLISP attempts to evaluate that
195 expression. If the expression evaluates successfully, XLISP prints the
196 result and then returns to the initial prompt waiting for another expression
197 to be typed.</p>
198
199 <a name="interactive-programming"></a>
200
201 <p><div class="box">
202
203 <p><b>Interactive Programming</b></p>
204
205 <p>There are several symbols maintained by the <nobr>read-eval-print</nobr>
206 loop:</p>
207
208 <p><table cellpadding="0" cellspacing="0"><tbody>
209 <tr>
210 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
211 <td><nobr>*</nobr></td>
212 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
213 <td width="100%"><nobr>the most recent result</nobr></td>
214 </tr>
215 <tr>
216 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
217 <td><nobr>**</nobr></td>
218 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
219 <td width="100%"><nobr>the second recent result</nobr></td>
220 </tr>
221 <tr>
222 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
223 <td><nobr>***</nobr></td>
224 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
225 <td width="100%"><nobr>the third recent result</nobr></td>
226 </tr>
227 <tr>
228 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
229 <td><nobr>+</nobr></td>
230 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
231 <td width="100%"><nobr>the most recent input expression</nobr></td>
232 </tr>
233 <tr>
234 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
235 <td><nobr>++</nobr></td>
236 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
237 <td width="100%"><nobr>the second recent input expression</nobr></td>
238 </tr>
239 <tr>
240 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
241 <td><nobr>+++</nobr></td>
242 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
243 <td width="100%"><nobr>the third recent input expression</nobr></td>
244 </tr>
245 <tr>
246 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
247 <td><nobr>&minus;</nobr></td>
248 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
249 <td width="100%">the expression currently being evaluated, becomes the
250 value of + at the end of the evaluation</td>
251 </tr>
252 </tbody></table></p>
253
254 <p>These symbols are for interactive programming. <nobr>It is</nobr> not
255 recommended to use them in program code.</p>
256
257 </div></p>
258
259 <a name="special-characters"></a>
260
261 <p><div class="box">
262
263 <p><b>Special Characters</b></p>
264
265 <p>When XLISP is running from a console <nobr>[not in</nobr> the Nyquist
266 <nobr>Java IDE]</nobr>, some control characters invoke operations:</p>
267
268 <p><table cellpadding="0" cellspacing="0"><tbody>
269 <tr>
270 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
271 <td><nobr>Control-c</nobr></td>
272 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
273 <td width="100%">executes the <a href="../reference/top-level.htm">top-level</a> function</td>
274 </tr>
275 <tr>
276 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
277 <td><nobr>Control-g</nobr></td>
278 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
279 <td width="100%">executes the <a href="../reference/clean-up.htm">clean-up</a> function</td>
280 </tr>
281 <tr>
282 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
283 <td><nobr>Control-p</nobr></td>
284 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
285 <td width="100%">executes the <a href="../reference/continue.htm">continue</a> function</td>
286 </tr>
287 <tr>
288 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
289 <td><nobr>Control-b</nobr></td>
290 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
291 <td width="100%">stops execution and enters the break command loop,
292 execution can be continued by typing Control-p <nobr>or
293 (<a href="../reference/continue.htm">continue</a>)</nobr></td>
294 </tr>
295 <tr>
296 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
297 <td><nobr>Control-e</nobr></td>
298 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
299 <td width="100%">turns on character echoing [Linux and <nobr>Mac OS X</nobr> only]</td>
300 </tr>
301 <tr>
302 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
303 <td><nobr>Control-f</nobr></td>
304 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
305 <td width="100%">turns off character echoing [Linux and <nobr>Mac OS X</nobr> only]</td>
306 </tr>
307 <tr>
308 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
309 <td><nobr>Control-t</nobr></td>
310 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
311 <td width="100%">evaluates the <a href="../reference/info.htm">info</a> function</td>
312 </tr>
313 <tr>
314 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
315 <td><nobr>Control-u</nobr></td>
316 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
317 <td width="100%">erases the entire input line</td>
318 </tr>
319 </tbody></table></p>
320
321 <p>Backspace and Delete characters erase the previous character on the input
322 line <nobr>[if any]</nobr>.</p>
323
324 </div></p>
325
326 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
327
328 <a name="break-loop"></a>
329
330 <hr>
331
332 <h2>4&nbsp; Break Loop</h2>
333
334 <hr>
335
336 <p>When XLISP encounters an error while evaluating an expression, it
337 attempts to handle the error in the following way:</p>
338
339 <dl>
340
341 <p><b>1.</b> If the symbol
342 <a href="../reference/global-breakenable.htm">*breakenable*</a> is true, the
343 message corresponding to the error is printed. <nobr>If the</nobr> error is
344 correctable, the correction message is printed.</p>
345
346 <dd>
347 <ul>
348
349 <li><p>If the symbol
350 <a href="../reference/global-tracenable.htm">*tracenable*</a> is true, a
351 trace back is printed. The number of entries printed depends on the value of
352 the symbol <a href="../reference/global-tracelimit.htm">*tracelimit*</a>.
353 <nobr>If this</nobr> symbol is set to something other than a number, the
354 entire trace back stack is printed.</p></li>
355
356 </ul>
357
358 <p>XLISP then enters a '<nobr>read-eval-print</nobr>' loop to allow the user
359 to examine the state of the interpreter in the context of the error. This
360 loop differs from the normal <nobr>top-level</nobr>
361 '<nobr>read-eval-print</nobr>' loop in that if the user invokes the
362 <a href="../reference/continue.htm">continue</a> function:</p>
363
364 <pre class="example">
365 1&gt; (continue)
366 </pre>
367
368 <p>XLISP will continue from a correctable error. <nobr>If the</nobr> user
369 invokes the <a href="../reference/clean-up.htm">clean-up</a> function:</p>
370
371 <pre class="example">
372 1&gt; (clean-up)
373 </pre>
374
375 <p>XLISP will abort the break loop and return to the top level or the next
376 lower numbered break loop. When in a break loop, XLISP prefixes the break
377 level to the normal prompt with a number.</p></dd>
378
379 <dt><p><b>2.</b> If the symbol
380 <a href="../reference/global-breakenable.htm">*breakenable*</a>
381 is <a href="../reference/nil.htm">NIL</a>, XLISP looks for a surrounding
382 <a href="../reference/errset.htm">errset</a> function:</p></dt>
383
384 </dl>
385
386 <ul>
387
388 <li type="circle"><p>If an error happened within the scope of an
389 <a href="../reference/errset.htm">errset</a> function, XLISP examines the
390 value of the <a href="../reference/errset.htm">errset</a> print flag.
391 <nobr>If this</nobr> flag is true, the error message is printed.
392 <nobr>In case</nobr> of an error, the
393 <a href="../reference/errset.htm">errset</a> function always <nobr>returns
394 <a href="../reference/nil.htm">NIL</a></nobr>.</p></li>
395
396 <li type="circle"><p>If there is no surrounding
397 <a href="../reference/errset.htm">errset</a> function, XLISP prints the
398 error message and returns to the top level.</p></li>
399
400 </ul>
401
402 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
403
404 <a name="data-types"></a>
405
406 <hr>
407
408 <h2>5&nbsp; Data Types</h2>
409
410 <hr>
411
412 <p>There are several different data types available to XLISP
413 programmers:</p>
414
415 <ul>
416 <li><nobr><a href="../reference/nil.htm">nil</a> - boolean false as well as the empty <a href="../reference/listp.htm">list</a></nobr></li>
417 <li><nobr><a href="../reference/arrayp.htm">array</a> - including <a href="../reference/hash.htm">hash</a>-tables</nobr></li>
418 <li><a href="../reference/characterp.htm">character</a></li>
419 <li><a href="../reference/numberp.htm">number</a></li>
420 <ul>
421 <li><a href="../reference/integerp.htm">fixnum</a> - integer number</li>
422 <li><a href="../reference/floatp.htm">flonum</a> - floating point number</li>
423 </ul>
424 <li><nobr><a href="../reference/consp.htm">cons</a> - a non-empty list, where a <a href="../reference/listp.htm">list</a> is of type <a href="../reference/consp.htm">cons</a> or <a href="../reference/nil.htm">nil</a></nobr></li>
425 <li><a href="../reference/objectp.htm">object</a></li>
426 <li><a href="../reference/streamp.htm">stream</a></li>
427 <ul>
428 <li><nobr><b>file-stream</b> - returned by <a href="../reference/open.htm">open</a></nobr></li>
429 <li><nobr><b>unnamed-stream</b> - returned by <a href="../reference/make-string-input-stream.htm">make-string-input-stream</a></nobr></li>
430 </ul>
431 <li><nobr><a href="../reference/stringp.htm">string</a></nobr></li>
432 <li><nobr><a href="../reference/symbolp.htm">symbol</a> - including keywords</nobr></li>
433 <li><nobr><b>subr</b> - built-in function</nobr></li>
434 <li><nobr><b>fsubr</b> - special form</nobr></li>
435 <li><nobr><b>closure</b> - user defined function</nobr></li>
436 <li><nobr><a href="../reference/filep.htm">file</a></nobr></li>
437 <li><nobr><a href="../reference/soundp.htm">sound</a> - a Nyquist sound</nobr></li>
438 </ul>
439
440 <p>See also the <nobr><a href="../reference/type-of.htm">type-of</a></nobr>
441 function.</p>
442
443 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
444
445 <a name="the-evaluator"></a>
446
447 <hr>
448
449 <h2>6&nbsp; The Evaluator</h2>
450
451 <hr>
452
453 <p>The process of evaluation in XLISP:</p>
454
455 <ul>
456
457 <li><p>The following Lisp objects evaluate to themselves:</p>
458
459 <ul>
460 <li><nobr><a href="../reference/stringp.htm">string</a></nobr></li>
461 <li><nobr><a href="../reference/integerp.htm">fixnum</a></nobr></li>
462 <li><nobr><a href="../reference/characterp.htm">character</a></nobr></li>
463 <li><nobr><a href="../reference/floatp.htm">flonum</a></nobr></li>
464 <li><nobr><a href="../reference/objectp.htm">object</a></nobr></li>
465 <li><nobr><a href="../reference/arrayp.htm">array</a></nobr></li>
466 <li><nobr><a href="../reference/streamp.htm">stream</a></nobr></li>
467 <li><nobr><b>subr</b> - built-in function</nobr></li>
468 <li><nobr><b>fsubr</b> - special form</nobr></li>
469 <li><nobr><b>closure</b> - user defined function</nobr></li>
470 </ul>
471 </li>
472
473 <li><p><font color="#000088"><b>Symbols</b></font> act as variables and are
474 evaluated by retrieving the value associated with their current
475 binding.</p></li>
476
477 <li><p><font color="#000088"><b>Lists</b></font> are evaluated by examining
478 the first element of the list and then taking one of the following
479 actions:</p></li>
480
481 <ul>
482
483 <li><p>If it is a <font color="#000088"><b>symbol</b></font>, the functional
484 binding of the symbol is retrieved.</p></li>
485
486 <li><p>If it is a <font color="#000088"><b>lambda expression</b></font>, a
487 closure is constructed for the function described by the lambda
488 expression.</p></li>
489
490 <li><p>If it is a <font color="#000088"><b>subr</b></font> [built-in
491 function], <font color="#000088"><b>fsubr</b></font> [special form] or <font
492 color="#000088"><b>closure</b></font> [user defined function], it stands for
493 itself.</p></li>
494
495 <li><p>Any other value is an <font color="#AA0000"><b>error</b></font>.</p></li>
496
497 </ul>
498
499 <p>Then, the value produced by the previous step is examined:</p>
500
501 <ul>
502
503 <li><p>If it is a <font color="#000088"><b>subr</b></font>
504 <nobr>[built-in</nobr> function] or <font
505 color="#000088"><b>closure</b></font> [user defined function], the remaining
506 list elements are evaluated and the subr or closure is called with these
507 evaluated expressions as arguments.</p></li>
508
509 <li><p>If it is an <font color="#000088"><b>fsubr</b></font> [special form],
510 the fsubr is called using the remaining list elements as arguments
511 [unevaluated].</p></li>
512
513 <li><p>If it is a<font color="#000088"><b> macro</b></font>, the macro is
514 expanded using the remaining list elements as arguments [unevaluated]. The
515 macro expansion is then evaluated in place of the original macro
516 call.</p></li>
517
518 </ul>
519
520 </ul>
521
522 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
523
524 <a name="lexical-conventions"></a>
525
526 <hr>
527
528 <h2>7&nbsp; Lexical Conventions</h2>
529
530 <hr>
531
532 <p>The following conventions must be followed when entering XLISP
533 programs:</p>
534
535 <ul>
536
537 <li><p>Comments in XLISP code begin with a semicolon character and continue
538 to the end of the line.</p></li>
539
540 <li><p>Symbol names in XLISP can consist of any sequence of non-blank
541 printable characters except the following:</p></li>
542
543 <p><table cellpadding="0" cellspacing="0"><tbody>
544 <tr>
545 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
546 <td class="button"><nobr>(</nobr></td>
547 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
548 <td width="100%"><nobr>opening parenthesis</nobr></td>
549 </tr>
550 <tr>
551 <td height="2px"></td>
552 </tr>
553 <tr>
554 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
555 <td class="button"><nobr>)</nobr></td>
556 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
557 <td width="100%"><nobr>closing parenthesis</nobr></td>
558 </tr>
559 <tr>
560 <td height="2px"></td>
561 </tr>
562 <tr>
563 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
564 <td class="button"><nobr>'</nobr></td>
565 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
566 <td width="100%"><nobr>single-quote</nobr></td>
567 </tr>
568 <tr>
569 <td height="2px"></td>
570 </tr>
571 <tr>
572 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
573 <td class="button"><nobr>`</nobr></td>
574 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
575 <td width="100%"><nobr>backquote</nobr></td>
576 </tr>
577 <tr>
578 <td height="2px"></td>
579 </tr>
580 <tr>
581 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
582 <td class="button"><nobr>,</nobr></td>
583 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
584 <td width="100%"><nobr>comma</nobr></td>
585 </tr>
586 <tr>
587 <td height="2px"></td>
588 </tr>
589 <tr>
590 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
591 <td class="button"><nobr>&quot;</nobr></td>
592 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
593 <td width="100%"><nobr>double-quote</nobr></td>
594 </tr>
595 <tr>
596 <td height="2px"></td>
597 </tr>
598 <tr>
599 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
600 <td class="button"><nobr>;</nobr></td>
601 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
602 <td width="100%"><nobr>semicolon</nobr></td>
603 </tr>
604 </tbody></table></p>
605
606 <li><p>Uppercase and lowercase characters are not distinguished within
607 symbol names. All lowercase characters are mapped to uppercase on
608 input.</p></li>
609
610 <li><p>Integer literals consist of a sequence of digits optionally beginning
611 with a '+' [plus] or '-' [minus]. The range of values an integer can
612 represent is limited by the size of a C 'long' value on the machine on which
613 XLISP is running. <nobr>Also be</nobr> aware that Nyquist doesn't check for
614 CPU register overflow with integer numbers, so for example if you add 1 to
615 the biggest Nyquist integer number, the result will be a negative
616 number.</p></li>
617
618 <li><p>Floating point literals consist of a sequence of digits optionally
619 beginning with a '+' [plus] or '-' [minus] and including an embedded decimal
620 point. The range of values a floating point number can represent is limited
621 by the size of a C 'float' [or 'double' on machines with 32 bit addresses]
622 on the machine on which XLISP is running.</p></li>
623
624 <li><p>Literal strings are sequences of characters surrounded by double
625 quotes. Within quoted strings the '\' [backslash] character is used to allow
626 non-printable characters to be included. The codes recognized are:</p></li>
627
628 <p><table cellpadding="0" cellspacing="0"><tbody>
629 <tr>
630 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
631 <td class="button"><nobr><code>\\</code></nobr></td>
632 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
633 <td width="100%">the character '\' [backslash]</td>
634 </tr>
635 <tr>
636 <td height="2px"></td>
637 </tr>
638 <tr>
639 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
640 <td class="button"><nobr><code>\n</code></nobr></td>
641 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
642 <td width="100%">newline</td>
643 </tr>
644 <tr>
645 <td height="2px"></td>
646 </tr>
647 <tr>
648 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
649 <td class="button"><nobr><code>\t</code></nobr></td>
650 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
651 <td width="100%">tab</td>
652 </tr>
653 <tr>
654 <td height="2px"></td>
655 </tr>
656 <tr>
657 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
658 <td class="button"><nobr><code>\r</code></nobr></td>
659 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
660 <td width="100%">return</td>
661 </tr>
662 <tr>
663 <td height="2px"></td>
664 </tr>
665 <tr>
666 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
667 <td class="button"><nobr><code>\f</code></nobr></td>
668 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
669 <td width="100%">form feed</td>
670 </tr>
671 <tr>
672 <td height="2px"></td>
673 </tr>
674 <tr>
675 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
676 <td class="button"><nobr><code>\<font color="#0000CC">nnn</font></code></nobr></td>
677 <td><nobr>&nbsp;&nbsp;-&nbsp;</nobr></td>
678 <td width="100%">the character whose octal code is 'nnn'</td>
679 </tr>
680 </tbody></table></p>
681
682 <p>An <a href="../misc/ascii-table.htm">ASCII</a> table
683 is provided with this version of the XLISP manual with all octal, decimal
684 and hexadecimal character values.</p>
685
686 </ul>
687
688 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
689
690 <a name="the-readtable"></a>
691
692 <hr>
693
694 <h2>8&nbsp; The Readtable</h2>
695
696 <hr>
697
698 <a name="constituent"></a><a name="white-space"></a>
699 <a name="tmacro"></a><a name="nmacro"></a>
700 <a name="sescape"></a><a name="mescape"></a>
701
702 <p>The behavior of the reader is controlled by a data structure called a
703 'readtable'. The reader uses the symbol
704 <a href="../reference/global-readtable.htm">*readtable*</a> to locate the
705 current readtable. This table controls the interpretation of input
706 characters. It is an array with 128 entries, one for each of the
707 <a href="../misc/ascii-table.htm">ASCII</a> character codes. Each
708 entry contains one of the following things:</p>
709
710 <p><table cellpadding="0" cellspacing="0"><tbody>
711 <tr>
712 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
713 <td class="button"><nobr><code>&nbsp;NIL</code></nobr></td>
714 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
715 <td><nobr>indicating an invalid character</nobr></td>
716 <td width="100%"><nobr>&nbsp;&nbsp; [see
717 <a href="../reference/nil.htm">nil</a>]</nobr></td>
718 </tr>
719 <tr>
720 <td height="2px"></td>
721 </tr>
722 <tr>
723 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
724 <td class="button"><nobr><code>:CONSTITUENT</code></nobr></td>
725 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
726 <td><nobr>indicating a symbol constituent</nobr></td>
727 <td width="100%"><nobr>&nbsp;&nbsp; [see
728 <a href="../reference/keyword-constituent.htm">:constituent</a>]</nobr></td>
729 </tr>
730 <tr>
731 <td height="2px"></td>
732 </tr>
733 <tr>
734 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
735 <td class="button"><nobr><code>:WHITE-SPACE</code></nobr></td>
736 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
737 <td><nobr>indicating a whitespace character</nobr></td>
738 <td width="100%"><nobr>&nbsp;&nbsp; [see
739 <a href="../reference/keyword-white-space.htm">:white-space</a>]</nobr></td>
740 </tr>
741 <tr>
742 <td height="2px"></td>
743 </tr>
744 <tr>
745 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
746 <td class="button"><nobr><code>(:TMACRO . <font color="#0000CC">function</font>)</code></nobr></td>
747 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
748 <td><nobr>terminating readmacro</nobr></td>
749 <td width="100%"><nobr>&nbsp;&nbsp; [see
750 <a href="../reference/keyword-tmacro.htm">:tmacro</a>]</nobr></td>
751 </tr>
752 <tr>
753 <td height="2px"></td>
754 </tr>
755 <tr>
756 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
757 <td class="button"><nobr><code>(:NMACRO . <font color="#0000CC">function</font>)</code></nobr></td>
758 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
759 <td><nobr>non-terminating readmacro</nobr></td>
760 <td width="100%"><nobr>&nbsp;&nbsp; [see
761 <a href="../reference/keyword-nmacro.htm">:nmacro</a>]</nobr></td>
762 </tr>
763 <tr>
764 <td height="2px"></td>
765 </tr>
766 <tr>
767 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
768 <td class="button"><nobr><code>:SESCAPE</code></nobr></td>
769 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
770 <td><nobr>single escape character '\'</nobr></td>
771 <td width="100%"><nobr>&nbsp;&nbsp; [see
772 <a href="../reference/keyword-sescape.htm">:sescape</a>]</nobr></td>
773 </tr>
774 <tr>
775 <td height="2px"></td>
776 </tr>
777 <tr>
778 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
779 <td class="button"><nobr><code>:MESCAPE</code></nobr></td>
780 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
781 <td><nobr>multiple escape character '|'</nobr></td>
782 <td width="100%"><nobr>&nbsp;&nbsp; [see
783 <a href="../reference/keyword-mescape.htm">:mescape</a>]</nobr></td>
784 </tr>
785 </tbody></table></p>
786
787 <p>In the case of <a href="../reference/keyword-tmacro.htm">:tmacro</a> and
788 <a href="../reference/keyword-nmacro.htm">:nmacro</a>, the 'fun' component
789 is a function. This can either be a built-in readmacro function or a
790 <a href="../reference/lambda.htm">lambda</a> expression. The
791 function should take two parameters. The first is the input stream and the
792 second is the character that caused the invocation of the readmacro. The
793 readmacro function should return
794 <a href="../reference/nil.htm">NIL</a> to indicate that the
795 character should be treated as white space or a value
796 <a href="../reference/cons.htm">cons</a>ed with
797 <a href="../reference/nil.htm">NIL</a> to indicate that the
798 readmacro should be treated as an occurence of the specified value. Of
799 course, the readmacro code is free to
800 <a href="../reference/read.htm">read</a> additional characters
801 from the input stream.</p>
802
803 <a name="quote"></a><a name="function"></a><a name="array"></a>
804 <a name="hexadecimal"></a><a name="octal"></a><a name="binary"></a>
805 <a name="character"></a><a name="comment"></a><a name="uninterned"></a>
806 <a name="backquote"></a><a name="comma"></a><a name="comma-at"></a>
807
808 <p>XLISP defines several useful read macros:</p>
809
810 <p><table cellpadding="0" cellspacing="0"><tbody>
811 <tr>
812 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
813 <td class="button"><nobr><code>'<font color="#0000CC">expression</font></code></nobr></td>
814 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
815 <td width="100%"><nobr>(<a href="../reference/quote.htm">quote</a>
816 <i>expr</i>)</nobr></td>
817 </tr>
818 <tr>
819 <td height="2px"></td>
820 </tr>
821 <tr>
822 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
823 <td class="button"><nobr><code>#'<font color="#0000CC">expression</font></code></nobr></td>
824 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
825 <td width="100%"><nobr>(<a href="../reference/function.htm">function</a>
826 <i>expr</i>)</nobr></td>
827 </tr>
828 <tr>
829 <td height="2px"></td>
830 </tr>
831 <tr>
832 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
833 <td class="button"><nobr><code>#(<font color="#0000CC">expression</font><font color="#008844">...</font>)</code></nobr></td>
834 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
835 <td width="100%"><nobr>an array of the specified expressions</nobr></td>
836 </tr>
837 <tr>
838 <td height="2px"></td>
839 </tr>
840 <tr>
841 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
842 <td class="button"><nobr><code>#x<font color="#0000CC">digits</font></code></nobr></td>
843 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
844 <td width="100%"><nobr>a hexadecimal number [0-9,A-F]</nobr></td>
845 </tr>
846 <tr>
847 <td height="2px"></td>
848 </tr>
849 <tr>
850 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
851 <td class="button"><nobr><code>#o<font color="#0000CC">digits</font></code></nobr></td>
852 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
853 <td width="100%"><nobr>an octal number [0-7]</nobr></td>
854 </tr>
855 <tr>
856 <td height="2px"></td>
857 </tr>
858 <tr>
859 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
860 <td class="button"><nobr><code>#b<font color="#0000CC">digits</font></code></nobr></td>
861 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
862 <td width="100%"><nobr>a binary number [0-1]</nobr></td>
863 </tr>
864 <tr>
865 <td height="2px"></td>
866 </tr>
867 <tr>
868 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
869 <td class="button"><nobr><code>#\<font color="#0000CC">character</font></code></nobr></td>
870 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
871 <td width="100%"><nobr>a single character</nobr></td>
872 </tr>
873 <tr>
874 <td height="2px"></td>
875 </tr>
876 <tr>
877 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
878 <td class="button"><nobr><code>#| <font color="#008844">...</font> |#</code></nobr></td>
879 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
880 <td width="100%"><nobr>a comment</nobr></td>
881 </tr>
882 <tr>
883 <td height="2px"></td>
884 </tr>
885 <tr>
886 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
887 <td class="button"><nobr><code>#:<font color="#0000CC">symbol</font></code></nobr></td>
888 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
889 <td width="100%"><nobr>an uninterned symbol</nobr></td>
890 </tr>
891 <tr>
892 <td height="2px"></td>
893 </tr>
894 <tr>
895 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
896 <td class="button"><nobr><code>`<font color="#0000CC">expression</font></code></nobr></td>
897 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
898 <td width="100%"><nobr>(<a href="../reference/backquote.htm">backquote</a>
899 <i>expr</i>)</nobr></td>
900 </tr>
901 <tr>
902 <td height="2px"></td>
903 </tr>
904 <tr>
905 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
906 <td class="button"><nobr><code>,<font color="#0000CC">expression</font></code></nobr></td>
907 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
908 <td width="100%"><nobr>(<a href="../reference/backquote.htm">comma</a>
909 <i>expr</i>)</nobr></td>
910 </tr>
911 <tr>
912 <td height="2px"></td>
913 </tr>
914 <tr>
915 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
916 <td class="button"><nobr><code>,@<font color="#0000CC">expression</font></code></nobr></td>
917 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
918 <td width="100%"><nobr>(<a href="../reference/backquote.htm">comma-at</a>
919 <i>expr</i>)</nobr></td>
920 </tr>
921 </tbody></table></p>
922
923 <a name="Tab"></a><a name="Newline"></a><a name="Space"></a>
924
925 <p>Characters names handled by the reader:</p>
926
927 <p><table cellpadding="0" cellspacing="0"><tbody>
928 <tr>
929 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
930 <td class="button"><nobr><code>#\Tab</code></nobr></td>
931 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
932 <td><nobr>horiz. tab</nobr></td>
933 <td><nobr>&nbsp;&nbsp; [<a href="../misc/ascii-table.htm">ASCII</a> decimal value 9]</nobr></td>
934 </tr>
935 <tr>
936 <td height="2px"></td>
937 </tr>
938 <tr>
939 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
940 <td class="button"><nobr><code>#\Newline</code></nobr></td>
941 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
942 <td><nobr>newline</nobr></td>
943 <td><nobr>&nbsp;&nbsp; [<a href="../misc/ascii-table.htm">ASCII</a> decimal value 10]</nobr></td>
944 </tr>
945 <tr>
946 <td height="2px"></td>
947 </tr>
948 <tr>
949 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
950 <td class="button"><nobr><code>#\Space</code></nobr></td>
951 <td><nobr>&nbsp;&nbsp;=&nbsp;&nbsp;</nobr></td>
952 <td><nobr>space</nobr></td>
953 <td><nobr>&nbsp;&nbsp; [<a href="../misc/ascii-table.htm">ASCII</a> decimal value 32]</nobr></td>
954 </tr>
955 </tbody></table></p>
956
957 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
958
959 <a name="lambda-lists"></a>
960
961 <hr>
962
963 <h2>9&nbsp; Lambda Lists</h2>
964
965 <a name="arguments"></a>
966
967 <hr>
968
969 <h2>9.1&nbsp; Arguments</h2>
970
971 <hr>
972
973 <p>There are several forms in XLISP that require that a <nobr>'lambda
974 list'</nobr> be specified. A lambda list is a definition of the arguments
975 accepted by a function.</p>
976
977 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
978
979 <a name="required-arguments"></a>
980
981 <hr>
982
983 <h2>9.1.1&nbsp; Required Arguments</h2>
984
985 <hr>
986
987 <p>The lambda list starts with 'required' arguments. Required arguments must
988 be specified in every call to the function.</p>
989
990 <p>The function '<nobr>print-x</nobr>' has exactly one required
991 <nobr>argument 'x'</nobr>:</p>
992
993 <pre class="example">
994 (defun print-x (x)
995 (print x))
996
997 (print-x 1) =&gt; 1
998 (print-x) =&gt; <font color="#AA0000">error: too few arguments</font>
999 (print-x 1 2) =&gt; <font color="#AA0000">error: too many arguments</font>
1000 </pre>
1001
1002 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
1003
1004 <a name="optional-arguments"></a>
1005
1006 <hr>
1007
1008 <h2>9.1.2&nbsp; Optional Arguments</h2>
1009
1010 <hr>
1011
1012 <p>The <nobr><a href="#required-arguments">Required Arguments</a></nobr> are followed by
1013 the <a href="../reference/lambda-keyword-optional.htm">&amp;optional</a>
1014 arguments. Optional arguments may be provided or omitted in a call. An
1015 initialization expression may be specified to provide a default value for an
1016 <a href="../reference/lambda-keyword-optional.htm">&amp;optional</a>
1017 argument if it is omitted from a call. If no initialization expression is
1018 specified, an omitted argument is initialized to
1019 <a href="../reference/nil.htm">NIL</a>.</p>
1020
1021 <p>It is also possible to provide the name of a 'supplied-p' variable that
1022 can be used to determine if a call provided a value for the argument or if
1023 the initialization expression was used. If specified, the 'supplied-p'
1024 variable will be bound to
1025 <a href="../reference/t.htm">&nbsp;T&nbsp;</a> if a value was
1026 specified in the call and
1027 <a href="../reference/nil.htm">NIL</a> if the default value was
1028 used.</p>
1029
1030 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
1031
1032 <a name="rest-argument"></a>
1033
1034 <hr>
1035
1036 <h2>9.1.3&nbsp; Rest Argument</h2>
1037
1038 <hr>
1039
1040 <p>The <nobr><a href="#optional-arguments">Optional Arguments</a></nobr> are followed by
1041 the <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a> argument.
1042 <nobr>The <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a></nobr>
1043 argument gets bound to the remainder of the argument list after the required
1044 and <a href="../reference/lambda-keyword-optional.htm">&amp;optional</a>
1045 arguments have been removed.</p>
1046
1047 <p><div class="box">
1048
1049 <p><b>Known Problems with the Rest Argument</b></p>
1050
1051 <p>A subtle problem arises if
1052 <nobr><a href="#optional-arguments">Optional Arguments</a></nobr> are used together with
1053 a <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a> argument:</p>
1054
1055 <pre class="example">
1056 (defun test (&amp;optional opt &amp;rest rest)
1057 (format t "opt = ~a, rest = ~a~%" opt rest))
1058
1059 (test 1) =&gt; opt = 1, rest = NIL
1060 (test 1 2) =&gt; opt = 1, rest = (2)
1061 (test 1 2 3) =&gt; opt = 1, rest = (2 3)
1062 </pre>
1063
1064 <p>Now the
1065 <a href="../reference/lambda-keyword-optional.htm">&amp;optional</a>
1066 argument is not optional anymore, there is no way to make the first argument
1067 appear in the <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a>
1068 list and not in the
1069 <a href="../reference/lambda-keyword-optional.htm">&amp;optional</a>
1070 variable. This is not a XLISP bug, this is a general Lisp phenomenon.
1071 <nobr>In Lisp</nobr> it's not a good idea to use
1072 <nobr><a href="#optional-arguments">Optional Arguments</a></nobr> together with a
1073 <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a> argument.</p>
1074
1075 <p>If a <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a>
1076 argument is used togethter with
1077 <nobr><a href="#keyword-arguments">Keyword Arguments</a></nobr>, then the keywords and
1078 their arguments appear in the list bound to the
1079 <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a></nobr>
1080 argument. This is not neccessarily a XLISP bug, this also happens with
1081 other Lisps. <nobr>In Lisp</nobr> it's also not a good idea to use
1082 <nobr><a href="#keyword-arguments">Keyword Arguments</a></nobr> together with a
1083 <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a> argument.</p>
1084
1085 <p><b>XLISP Bug:</b> <nobr>If the</nobr> number of elements in a
1086 <a href="../reference/lambda-keyword-rest.htm">&amp;rest</a> list
1087 is odd, then <a href="../reference/lambda-keyword-key.htm">&amp;key</a>
1088 variables have wrong values:</p>
1089
1090 <pre class="example">
1091 (defun test (&amp;rest rest &amp;key (key t))
1092 (format t "rest = ~a, key = ~a~%" rest key))
1093
1094 (test 1 :key 'a) =&gt; rest = (1 :KEY A), key = T <font color="#AA0000">; wrong KEY value</font>
1095 (test 1 2 :key 'a) =&gt; rest = (1 2 :KEY A), key = A <font color="#008844">; quirk, but correct KEY value</font>
1096 (test 1 2 3 :key 'a)) =&gt; rest = (1 2 3 :KEY A), key = T <font color="#AA0000">; again wrong KEY value</font>
1097 </pre>
1098
1099 </div></p>
1100
1101 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
1102
1103 <a name="keyword-arguments"></a>
1104
1105 <hr>
1106
1107 <h2>9.1.4&nbsp; Keyword Arguments</h2>
1108
1109 <hr>
1110
1111 <p>The <nobr><a href="#rest-argument">Rest Argument</a></nobr> is
1112 followed by the <a href="../reference/lambda-keyword-key.htm">&amp;key</a>
1113 arguments. When a keyword argument is passed to a function, a pair of values
1114 appears in the argument list. The first expression in the pair should
1115 evaluate to a keyword symbol [a symbol that begins with a <nobr>colon
1116 ':'].</nobr> The value of the second expression is the value of the keyword
1117 argument.</p>
1118
1119 <p>Like <a href="../reference/lambda-keyword-optional.htm">&amp;optional</a>
1120 arguments, <a href="../reference/lambda-keyword-key.htm">&amp;key</a> arguments can
1121 have initialization expressions and 'supplied-p' variables. In addition, it
1122 is possible to specify the keyword to be used in a function call. If no
1123 keyword is specified, the keyword obtained by adding a colon ':' to the
1124 beginning of the keyword argument symbol is used.</p>
1125
1126 <p>In other words, if the keyword argument symbol is:</p>
1127
1128 <pre class="example">
1129 foo
1130 </pre>
1131
1132 <p>the keyword will be:</p>
1133
1134 <pre class="example">
1135 :foo
1136 </pre>
1137
1138 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
1139
1140 <a name="auxiliary-variables"></a>
1141
1142 <hr>
1143
1144 <h2>9.1.5&nbsp; Auxiliary Variables</h2>
1145
1146 <hr>
1147
1148 <p>The <nobr><a href="#keyword-arguments">Keyword Arguments</a></nobr> are followed by
1149 the <a href="../reference/lambda-keyword-aux.htm">&amp;aux</a> variables.
1150 These are local variables that are bound during the evaluation of the
1151 function body. It is possible to have initialization expressions for the
1152 <a href="../reference/lambda-keyword-aux.htm">&amp;aux</a> variables.</p>
1153
1154 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to Top</a></nobr></p>
1155
1156 <a name="lambda-list-syntax"></a>
1157
1158 <hr>
1159
1160 <h2>9.2&nbsp; Lambda List Syntax</h2>
1161
1162 <hr>
1163
1164 <p>Here is the complete syntax for lambda lists:</p>
1165
1166 <p><table cellpadding="0" cellspacing="0"><tbody>
1167 <tr>
1168 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1169 <td width="100%" colspan="2"><nobr>(<i>required-arg</i> ...</nobr></td>
1170 </tr>
1171 <tr>
1172 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1173 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1174 <td width="100%"><nobr>[<b>&amp;optional</b> [<i>optional-arg</i> | (<i>optional-arg</i> [<i>init-form</i> [<i>supplied-var</i>]])] ... ]</nobr></td>
1175 </tr>
1176 <tr>
1177 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1178 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1179 <td width="100%"><nobr>[<b>&amp;rest</b> <i>rest-arg</i>]</nobr></td>
1180 </tr>
1181 <tr>
1182 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1183 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1184 <td width="100%"><nobr>[<b>&amp;key</b> [<i>key-arg</i> | ([<i>key-arg</i> | (<i>keyword</i> <i>key-arg</i>)] [<i>init-form</i> [<i>supplied-var</i>]]) ...] <b>&amp;allow-other-keys</b>]</nobr></td>
1185 </tr>
1186 <tr>
1187 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1188 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1189 <td width="100%"><nobr>[<b>&amp;aux</b> [<i>aux-var</i> | (<i>aux-var</i> [<i>init-form</i>])] ... ])</nobr></td>
1190 </tr>
1191 </tbody></table></p>
1192
1193 <p>where:</p>
1194
1195 <p><table cellpadding="0" cellspacing="0"><tbody>
1196 <tr>
1197 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1198 <td align="right"><nobr><i>required-arg</i></nobr></td>
1199 <td><nobr>&nbsp;&mdash;&nbsp;</nobr></td>
1200 <td width="100%">is a <a href="#required-arguments">required</a> argument symbol</td>
1201 </tr>
1202 <tr>
1203 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1204 <td align="right"><nobr><i>optional-arg</i></nobr></td>
1205 <td><nobr>&nbsp;&mdash;&nbsp;</nobr></td>
1206 <td width="100%">is an <a href="#optional-arguments">&amp;optional</a> argument symbol</td>
1207 </tr>
1208 <tr>
1209 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1210 <td align="right"><nobr><i>rest-arg</i></nobr></td>
1211 <td><nobr>&nbsp;&mdash;&nbsp;</nobr></td>
1212 <td width="100%">is the <a href="#rest-argument">&amp;rest</a> argument symbol</td>
1213 </tr>
1214 <tr>
1215 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1216 <td align="right"><nobr><i>key-arg</i></nobr></td>
1217 <td><nobr>&nbsp;&mdash;&nbsp;</nobr></td>
1218 <td width="100%">is a <a href="#keyword-arguments">&amp;key</a> argument symbol</td>
1219 </tr>
1220 <tr>
1221 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1222 <td align="right"><nobr><i>keyword</i></nobr></td>
1223 <td><nobr>&nbsp;&mdash;&nbsp;</nobr></td>
1224 <td width="100%">is a <a href="#keyword-arguments">keyword</a> symbol</td>
1225 </tr>
1226 <tr>
1227 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1228 <td align="right"><nobr><i>aux-var</i></nobr></td>
1229 <td><nobr>&nbsp;&mdash;&nbsp;</nobr></td>
1230 <td width="100%">is an <a href="#auxiliary-variables">auxiliary</a> variable symbol</td>
1231 </tr>
1232 <tr>
1233 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1234 <td align="right"><nobr><i>init-form</i></nobr></td>
1235 <td><nobr>&nbsp;&mdash;&nbsp;</nobr></td>
1236 <td width="100%">is an initialization expression</td>
1237 </tr>
1238 <tr>
1239 <td><nobr><code>&nbsp;&nbsp;</code></nobr></td>
1240 <td align="right"><nobr><i>supplied-var</i></nobr></td>
1241 <td><nobr>&nbsp;&mdash;&nbsp;</nobr></td>
1242 <td width="100%">is a supplied-p variable symbol</td>
1243 </tr>
1244 </tbody></table></p>
1245
1246 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
1247
1248 <hr>
1249
1250 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
1251 <a href="contents.htm">Contents</a> |
1252 <a href="../tutorials/tutorials.htm">Tutorials</a> |
1253 <a href="../examples/examples.htm">Examples</a> |
1254 <a href="../reference/reference-index.htm">Reference</a>
1255
1256 </body></html>