| 1 |
<html><head> |
| 2 |
|
| 3 |
<title>cl:multiple-value-call</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> - |
| 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-call</h1> |
| 52 |
|
| 53 |
<hr> |
| 54 |
|
| 55 |
<p>The <nobr>cl:<b>multiple-value-call</b></nobr> macro applies a function |
| 56 |
to a list of return values:</p> |
| 57 |
|
| 58 |
<p><div class="box"> |
| 59 |
|
| 60 |
<dl> |
| 61 |
<dt>(cl:<b>multiple-value-call</b> <i>function</i> [<i>expr1</i> ...])</dt> |
| 62 |
<dd><i>function</i> - a Lisp expression evaluating to a function call<br> |
| 63 |
<i>exprN</i> - arbitrary Lisp expressions<br> |
| 64 |
returns - the values returned by the function</dd> |
| 65 |
</dl> |
| 66 |
|
| 67 |
</div></p> |
| 68 |
|
| 69 |
<pre class="example"> |
| 70 |
(defmacro <font color="#0000CC">cl:multiple-value-call</font> (function &rest exprs) |
| 71 |
(let (args) |
| 72 |
(dolist (expr exprs) |
| 73 |
(setq <font color="#AA5500">cl:*multiple-values*</font> nil) |
| 74 |
(let* ((result (eval expr))) |
| 75 |
(if <font color="#AA5500">cl:*multiple-values*</font> |
| 76 |
(dolist (rslt <font color="#AA5500">*rslt*</font>) (push rslt args)) |
| 77 |
(push result args)))) |
| 78 |
(setq args (reverse args)) |
| 79 |
`(progn |
| 80 |
(setq <font color="#AA5500">cl:*multiple-values*</font> nil) |
| 81 |
(apply ,function ',args))) |
| 82 |
</pre> |
| 83 |
|
| 84 |
<p>The <nobr>cl:<b>multiple-value-call</b></nobr> macro first evaluates the |
| 85 |
expressions and collects all return values in a single list, then the |
| 86 |
'function' form is evaluated and the resulting function call is applied to |
| 87 |
the list of values.</p> |
| 88 |
|
| 89 |
<p>Before applying the function to the list of values the |
| 90 |
<nobr><a href="global-multiple-values.htm">cl:*multiple-values*</a></nobr> |
| 91 |
variable is set to <a href="../../reference/nil.htm">NIL</a>, the final value of |
| 92 |
<nobr><a href="global-multiple-values.htm">cl:*multiple-values*</a></nobr> |
| 93 |
depends on the 'function' argument.</p> |
| 94 |
|
| 95 |
<p>Examples:</p> |
| 96 |
|
| 97 |
<pre class="example"> |
| 98 |
> (funcall #'+ |
| 99 |
(cl:values 1 2) |
| 100 |
(cl:values 3 4)) |
| 101 |
4 <font color="#008844">; (apply #'+ (1 3))</font> |
| 102 |
|
| 103 |
> (cl:multiple-value-call #'+ |
| 104 |
(cl:values 1 2) |
| 105 |
(cl:values 3 4)) |
| 106 |
10 <font color="#008844">; (apply #'+ (1 2 3 4))</font> |
| 107 |
</pre> |
| 108 |
|
| 109 |
<p><nobr> <a href="#top">Back to top</a></nobr></p> |
| 110 |
|
| 111 |
<hr> |
| 112 |
|
| 113 |
<a href="../../start.htm">Nyquist / XLISP 2.0</a> - |
| 114 |
<a href="../../manual/contents.htm">Contents</a> | |
| 115 |
<a href="../../tutorials/tutorials.htm">Tutorials</a> | |
| 116 |
<a href="../examples.htm">Examples</a> | |
| 117 |
<a href="../../reference/reference-index.htm">Reference</a> |
| 118 |
|
| 119 |
</body></html> |