Debian Codegraph @

docsrc/xlisp/xlisp-doc/reference/macroexpand-1.htm

raw
1 <html><head><title>XLISP macroexpand-1</title>
2
3 <link rel="stylesheet" type="text/css" href="reference.css">
4
5 </head>
6
7 <body>
8
9 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
10 <a href="../manual/contents.htm">Contents</a> |
11 <a href="../tutorials/tutorials.htm">Tutorials</a> |
12 <a href="../examples/examples.htm">Examples</a> |
13 <a href="reference-index.htm">Reference</a>
14
15 <hr>
16
17 <h1>macroexpand-1</h1>
18
19 <hr>
20
21 <p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
22 <tr valign="top">
23 <td><nobr>Type:</nobr></td>
24 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
25 <td width="100%"><nobr>function (subr)</nobr></td>
26 </tr>
27 <tr valign="top">
28 <td><nobr>Source:</nobr></td>
29 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
30 <td width="100%"><nobr>xlbfun.c</nobr></td>
31 </tr>
32 </tbody></table></p>
33
34 <h2>Syntax</h2>
35
36 <dl>
37 <dt>(macroexpand-1 <i>form</i>)</dt>
38 <dd><i>form</i> - a macro form<br>
39 returns - the macro expansion</dd>
40 </dl>
41
42 <h2>Description</h2>
43
44 <p>The 'macroexpand-1' function takes a 'form' and expands the first level
45 of the macro definition used in the 'form'. The function returns the
46 expansion. If the 'form' does not contain a macro, the form is returned
47 unaltered.</p>
48
49 <h2>Examples</h2>
50
51 <pre class="example">
52 (defmacro plus (n1 n2) `(+ ,n1 ,n2)) <font color="#008844">; define PLUS macro</font>
53 (plus 1 2) <font color="#008844">; returns 3</font>
54 (macroexpand '(plus 3 4)) <font color="#008844">; returns (+ 3 4)</font>
55 (macroexpand-1 '(plus 3 4)) <font color="#008844">; returns (+ 3 4)</font>
56
57 (defmacro pl (p1 p2) `(plus ,p1 ,p2)) <font color="#008844">; define PL macro using PLUS</font>
58 (pl 3 4) <font color="#008844">; returns 7</font>
59 (macroexpand '(pl 3 4)) <font color="#008844">; returns (+ 3 4)</font>
60 (macroexpand-1 '(pl 3 4)) <font color="#008844">; returns (PLUS 3 4)</font>
61 </pre>
62
63 <p><b>Common Lisp:</b> Common Lisp returns 2 values for its result of
64 'macroexpand-1', the expanded form and a
65 <a href="t.htm">&nbsp;T&nbsp;</a> or
66 <a href="nil.htm">NIL</a> value that indicates if the form was a
67 macro. XLISP returns only the expanded form. Common Lisp also supports an
68 optional argument in 'macroexpand-1' for the environment of the expansion.
69 XLISP does not support this optional argument.</p>
70
71 <p>See the
72 <a href="../manual/xlisp-man-012.htm#macroexpand-1">macroexpand-1</a>
73 function in the <nobr>XLISP 2.0</nobr> manual.</p>
74
75 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to Top</nobr></a></p>
76
77 <hr>
78
79 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
80 <a href="../manual/contents.htm">Contents</a> |
81 <a href="../tutorials/tutorials.htm">Tutorials</a> |
82 <a href="../examples/examples.htm">Examples</a> |
83 <a href="reference-index.htm">Reference</a>
84
85 </body></html>