Debian Codegraph @

docsrc/xlisp/xlisp-doc/examples/common-lisp/multiple-value-prog1.htm

raw
1 <html><head>
2
3 <title>cl:multiple-value-prog1</title>
4
5 <style type="text/css">
6 .example {
7 color: #000000;
8 background-color: #F5F5F5;
9 padding: 8px;
10 border: #808080;
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: #808080;
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: #808080;
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="../../manual/contents.htm">Contents</a> |
45 <a href="../../tutorials/tutorials.htm">Tutorials</a> |
46 <a href="../examples.htm">Examples</a> |
47 <a href="../../reference/reference-index.htm">Reference</a>
48
49 <hr>
50
51 <h1>cl:multiple-value-prog1</h1>
52
53 <hr>
54
55 <p>The <nobr>cl:<b>multiple-value-prog1</b></nobr> macro is like
56 <a href="../../reference/prog1.htm">prog1</a>, but it can handle multiple
57 values:</p>
58
59 <p><div class="box">
60
61 <dl>
62 <dt>(cl:<b>multiple-value-prog1</b> <i>expr1</i> [<i>expr2</i> ...])</dt>
63 <dd><i>exprN</i> - arbitrary Lisp expressions<br>
64 returns - the values returned by the first expression</dd>
65 </dl>
66
67 </div></p>
68
69 <pre class="example">
70 (defmacro <font color="#0000CC">cl:multiple-value-prog1</font> (expr &amp;rest body)
71 (setq <font color="#AA5500">cl:*multiple-values*</font> nil)
72 (let* ((result (eval expr)))
73 (if <font color="#AA5500">cl:*multiple-values*</font>
74 `(progn ,@body
75 (setq <font color="#AA5500">*rslt*</font> ',<font color="#AA5500">*rslt*</font>
76 <font color="#AA5500">cl:*multiple-values*</font> t)
77 ',result)
78 `(progn ,@body ',result))))
79 </pre>
80
81 <p>The <nobr>cl:<b>multiple-value-prog1</b></nobr> macro evaluates the first
82 expression and saves all the values returned by the evaluation. <nobr>It
83 then</nobr> evaluates each of the following expressions from left to right,
84 discarding their values. After the evaluation is finished, the
85 <nobr><a href="global-multiple-values.htm">cl:*multiple-values*</a></nobr>
86 and <a href="../../reference/global-rslt.htm">*rslt*</a> variables are
87 restored and the primary value from evaluating the fist expression is
88 returned.</p>
89
90 <p><nobr>The
91 <a href="global-multiple-values.htm">cl:*multiple-values*</a></nobr>
92 variable <nobr>is <a href="../../reference/t.htm">&nbsp;T&nbsp;</a></nobr>
93 if evaluating the first expression returns multiple values and
94 <a href="../../reference/nil.htm">NIL</a> with a normal return value.</p>
95
96 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
97
98 <hr>
99
100 <a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
101 <a href="../../manual/contents.htm">Contents</a> |
102 <a href="../../tutorials/tutorials.htm">Tutorials</a> |
103 <a href="../examples.htm">Examples</a> |
104 <a href="../../reference/reference-index.htm">Reference</a>
105
106 </body></html>