summaryrefslogtreecommitdiff
path: root/docsrc/xlisp/xlisp-doc/reference/lambda-keyword-rest.htm
diff options
context:
space:
mode:
Diffstat (limited to 'docsrc/xlisp/xlisp-doc/reference/lambda-keyword-rest.htm')
-rw-r--r--docsrc/xlisp/xlisp-doc/reference/lambda-keyword-rest.htm104
1 files changed, 104 insertions, 0 deletions
diff --git a/docsrc/xlisp/xlisp-doc/reference/lambda-keyword-rest.htm b/docsrc/xlisp/xlisp-doc/reference/lambda-keyword-rest.htm
new file mode 100644
index 0000000..639465d
--- /dev/null
+++ b/docsrc/xlisp/xlisp-doc/reference/lambda-keyword-rest.htm
@@ -0,0 +1,104 @@
+<html><head><title>XLISP &amp;rest</title>
+
+<link rel="stylesheet" type="text/css" href="reference.css">
+
+</head>
+
+<body>
+
+<a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
+<a href="../manual/contents.htm">Contents</a> |
+<a href="../tutorials/tutorials.htm">Tutorials</a> |
+<a href="../examples/examples.htm">Examples</a> |
+<a href="reference-index.htm">Reference</a>
+
+<hr>
+
+<h1>&amp;rest</h1>
+
+<hr>
+
+<p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
+<tr valign="top">
+ <td><nobr>Type:</nobr></td>
+ <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
+ <td width="100%"><nobr>keyword</nobr></td>
+</tr>
+<tr valign="top">
+ <td><nobr>Source:</nobr></td>
+ <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
+ <td width="100%"><nobr>xleval.c</nobr></td>
+</tr>
+</tbody></table></p>
+
+<h2>Syntax</h2>
+
+<dl>
+<dt>&amp;rest [<i>rest-arg</i>]</dt>
+<dd><i>rest-arg</i> - rest argument symbol</dd>
+</dl>
+
+<h2>Description</h2>
+
+<p>In XLISP, there are several times that you define a formal argument list
+for a body of code like
+<nobr><a href="defun.htm">defun</a> ,</nobr>
+<nobr><a href="defmacro.htm">defmacro</a> ,</nobr>
+<a href="keyword-answer.htm">:answer</a> and
+<a href="lambda.htm">lambda</a>. All of the formal arguments that
+are defined are required to appear in the invocation of the defined function
+or operation. If there are any
+<a href="lambda-keyword-optional.htm">&amp;optional</a> arguments defined, they will
+be filled in order. If there is a '&amp;rest' argument defined, and all
+the required formal arguments and
+<a href="lambda-keyword-optional.htm">&amp;optional</a> arguments are filled, any and
+all further parameters will be passed into the function via the 'rarg'
+argument. There can be only one 'rest-arg' argument for '&amp;rest'. If
+there are insufficient parameters for any of the
+<a href="lambda-keyword-optional.htm">&amp;optional</a> or '&amp;rest' arguments,
+they will contain <a href="nil.htm">NIL</a>. At the end of the
+function or operation execution, these local symbols and their values are
+removed.</p>
+
+<h2>Examples</h2>
+
+<pre class="example">
+(defun foo <font color="#008844">; define function FOO</font>
+ (a b &amp;optional c d &amp;rest e) <font color="#008844">; with some of each argument</font>
+ (print a) (print b)
+ (print c) (print d) <font color="#008844">; print out each</font>
+ (print e))
+(foo) <font color="#008844">; error: too few arguments</font>
+(foo 1) <font color="#008844">; error: too few arguments</font>
+(foo 1 2) <font color="#008844">; prints 1 2 NIL NIL NIL</font>
+(foo 1 2 3) <font color="#008844">; prints 1 2 3 NIL NIL</font>
+(foo 1 2 3 4) <font color="#008844">; prints 1 2 3 4 NIL</font>
+(foo 1 2 3 4 5) <font color="#008844">; prints 1 2 3 4 (5)</font>
+(foo 1 2 3 4 5 6 7 8 9) <font color="#008844">; prints 1 2 3 4 (5 6 7 8 9)</font>
+
+(defun my-add <font color="#008844">; define function MY-ADD</font>
+ (num1 &amp;rest num-list &amp;aux sum) <font color="#008844">; with 1 arg, rest, 1 aux var</font>
+ (setq sum num1) <font color="#008844">; clear SUM</font>
+ (dotimes (i (length num-list) ) <font color="#008844">; loop through rest list</font>
+ (setq sum (+ sum (car num-list))) <font color="#008844">; add the number to sum</font>
+ (setq num-list (cdr num-list))) <font color="#008844">; and remove num from list</font>
+ sum) <font color="#008844">; return sum when finished</font>
+(my-add 1 2 3 4) <font color="#008844">; returns 10</font>
+(my-add 5 5 5 5 5) <font color="#008844">; returns 25</font>
+</pre>
+
+<p>See the
+<a href="../manual/xlisp-man-009.htm#9-1-3">&amp;rest</a>
+keyword in the <nobr>XLISP 2.0</nobr> manual.</p>
+
+<p><nobr>&nbsp;&nbsp;<a href="#top">Back to Top</nobr></a></p>
+
+<hr>
+
+<a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
+<a href="../manual/contents.htm">Contents</a> |
+<a href="../tutorials/tutorials.htm">Tutorials</a> |
+<a href="../examples/examples.htm">Examples</a> |
+<a href="reference-index.htm">Reference</a>
+
+</body></html> \ No newline at end of file