Debian Codegraph @

docsrc/xlisp/xlisp-doc/examples/common-lisp/values.htm

raw
1 <html><head>
2
3 <title>cl:values</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:values</h1>
52
53 <hr>
54
55 <p>The <nobr>cl:<b>values</b></nobr> function evaluates all given Lisp
56 expressions and returns the results as multiple values:</p>
57
58 <p><div class="box">
59
60 <dl>
61 <dt>(cl:<b>values</b> [<i>expr1</i> ...])</dt>
62 <dd><i>exprN</i> - an arbitrary Lisp expression<br>
63 returns - the results of evaluating the expressions, as multiple values</dd>
64 </dl>
65
66 </div></p>
67
68 <pre class="example">
69 (defun <font color="#0000CC">cl:values</font> (&amp;rest exprs)
70 (setq <font color="#AA5500">*rslt*</font> exprs
71 <font color="#AA5500">cl:*multiple-values*</font> t)
72 (first exprs))
73 </pre>
74
75 <p>The primary return value <nobr>[the result</nobr> from evaluating the
76 first expression] is returned by the <nobr>cl:<b>values</b></nobr> function
77 and a list with the results of evaluating all expressions is assigned to the
78 Nyquist <a href="../../reference/global-rslt.htm">*rslt*</a> variable.
79 <nobr>If no</nobr> expressions are given,
80 <a href="..././reference/nil.htm">NIL</a> is returned and the
81 <a href="../../reference/global-rslt.htm">*rslt*</a> variable is set
82 <nobr>to <a href="../../reference/nil.htm">NIL</a></nobr>.</p>
83
84 <p><nobr>The
85 <a href="global-multiple-values.htm">cl:*multiple-values*</a></nobr>
86 variable is set
87 <nobr>to <a href="../../reference/t.htm">&nbsp;T&nbsp;</a></nobr>
88 to indicate that multiple values are returned.</p>
89
90 <p>Examples:</p>
91
92 <pre class="example">
93 (cl:values 1 2 3) =&gt; 1 <font color="#008844">; primary value</font>
94 *rslt* =&gt; (1 2 3) <font color="#008844">; all values</font>
95
96 (cl:values 'a 'b) =&gt; A <font color="#008844">; primary value</font>
97 *rslt* =&gt; (A B) <font color="#008844">; all values</font>
98
99 &gt; (cl:multiple-value-bind (a b c)
100 (cl:values 1 2 3)
101 (list a b c))
102 (1 2 3)
103 </pre>
104
105 <p>See
106 <nobr><a href="multiple-value-bind.htm">cl:multiple-value-bind</a></nobr>,
107 <a href="../../reference/list.htm">list</a>,
108 <a href="../../reference/global-rslt.htm">*rslt*</a>.</p>
109
110 <p><div class="box">
111
112 <p><b>Known Limitations</b></p>
113
114 <p><b>1.</b> In Nyquist/XLISP, <nobr>cl:<b>values</b></nobr> cannot be
115 used as argument to <a href="../../reference/setf.htm">setf</a>. <nobr>But
116 this</nobr> is not a real problem, because the values are stored as a
117 simple list in the <a href="../../reference/global-rslt.htm">*rslt*</a>
118 variable, where they can be manipulated with any arbitrary Lisp
119 functions, not only <nobr>with
120 <a href="../../reference/setf.htm">setf</a></nobr>.</p>
121
122 <p><b>2.</b> In <nobr>Common Lisp</nobr> there exists the option to return
123 <nobr>'no value</nobr>' by calling the 'values' function with no arguments.
124 <nobr>In Nyquist/XLISP</nobr> there is no <nobr>built-in</nobr> way to
125 return '<nobr>no value</nobr>' from a function. <nobr>The symbol</nobr>
126 <a href="../../reference/global-unbound.htm">*unbound*</a> cannot be used for
127 this because in <nobr>Common Lisp</nobr>, if '<nobr>no value</nobr>' is
128 assigned to a symbol as variable value, the new value will be
129 <a href="../../reference/nil.htm">NIL</a> and not
130 <a href="../../reference/global-unbound.htm">*unbound*</a>.</p>
131
132 <p>In Nyquist/XLISP, the cl:<b>values</b> function, if called with no
133 arguments, always returns <a href="../../reference/nil.htm">NIL</a>, and the
134 <a href="../../reference/global-rslt.htm">*rslt*</a> variable will be
135 set <nobr>to <a href="../../reference/nil.htm">NIL</a>, too:</nobr></p>
136
137 <pre class="example">
138 (cl:values) =&gt; NIL <font color="#008844">; primary value</font>
139 *rslt* =&gt; NIL <font color="#008844">; all values</font>
140
141 (cl:values nil) =&gt; NIL <font color="#008844">; primary value</font>
142 *rslt* =&gt; (NIL) <font color="#008844">; all values</font>
143 </pre>
144
145 <p>Maybe this observation helps to write a '<nobr>no values</nobr>' test if
146 anybody really <nobr>needs it</nobr>.</p>
147
148 </div></p>
149
150 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to top</a></nobr></p>
151
152 <hr>
153
154 <a href="../../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
155 <a href="../../manual/contents.htm">Contents</a> |
156 <a href="../../tutorials/tutorials.htm">Tutorials</a> |
157 <a href="../examples.htm">Examples</a> |
158 <a href="../../reference/reference-index.htm">Reference</a>
159
160 </body></html>