| 1 |
<?xml version="1.0" encoding="utf-8"?> |
| 2 |
<!DOCTYPE book [ |
| 3 |
<!ENTITY % eclent SYSTEM "ecl.ent"> |
| 4 |
%eclent; |
| 5 |
]> |
| 6 |
<book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en"> |
| 7 |
<chapter xml:id="Macros"> |
| 8 |
<title>Macros</title> |
| 9 |
<para>A <firstterm>defmacro lambda-list</firstterm> is a lambda-list-like construct that is used as |
| 10 |
the third element in the <literal>defmacro</literal> form,</para> |
| 11 |
<screen> |
| 12 |
(defmacro <replaceable>name</replaceable> <replaceable>efmacro-lambda-list</replaceable> [<replaceable>declaration</replaceable> | <replaceable>doc-string</replaceable>] {<replaceable>form</replaceable>}*) |
| 13 |
</screen> |
| 14 |
<para>The description of defmacro lambda-lists in &Steele84; is quite |
| 15 |
ambiguous. &ECL; employs the following syntax.</para> |
| 16 |
<para>The complete syntax of a defmacro lambda-list is:</para> |
| 17 |
<screen> |
| 18 |
( [&whole <replaceable>var</replaceable>] |
| 19 |
[&environment <replaceable>var</replaceable>] |
| 20 |
[<replaceable>pseudo-var</replaceable>] |
| 21 |
[&optional {var | ( pseudo-var [initform [pseudo-var]] )}] |
| 22 |
{[{&rest | &body} pseudo-var] |
| 23 |
[&key {var |
| 24 |
| ({var | (keyword pseudo-var)} [initform [pseudo-var]])}* |
| 25 |
[&allow-other-keys]] |
| 26 |
[&aux {var | (pseudo-var [initform])}*] |
| 27 |
| . var } |
| 28 |
) |
| 29 |
</screen> |
| 30 |
<para role="continues">where <replaceable>pseudo-var</replaceable> is either a symbol or a list of the following |
| 31 |
form:</para> |
| 32 |
<screen> |
| 33 |
( {pseudo-var}* |
| 34 |
[&optional {var | (pseudo-var [initform [pseudo-var]])}*] |
| 35 |
{[{&rest | &body} pseudo-var] |
| 36 |
[&key {var | ({var | (keyword pseudo-var)} |
| 37 |
[initform [pseudo-var]])}* |
| 38 |
[&allow-other-keys]] |
| 39 |
[&aux {var | (pseudo-var [initform])}] |
| 40 |
| . var } |
| 41 |
) |
| 42 |
</screen> |
| 43 |
<para>The defmacro lambda-list keyword <literal>&whole</literal> may appear only at the |
| 44 |
top-level, first in the defmacro lambda-list. It is not allowed within |
| 45 |
<replaceable>pseudo-var</replaceable>. Use of the <literal>&whole</literal> keyword does not affect the |
| 46 |
processing of the rest of the defmacro lambda-list:</para> |
| 47 |
<programlisting> |
| 48 |
(defmacro foo (&whole w x y) ...) |
| 49 |
</programlisting> |
| 50 |
<para>and</para> |
| 51 |
<programlisting> |
| 52 |
(defmacro foo (x y) ...) |
| 53 |
</programlisting> |
| 54 |
<para role="continues">both bind the variables <literal>x</literal> and <literal>y</literal> to the second and the |
| 55 |
third elements, respectively, of macro forms of <literal>foo</literal>.</para> |
| 56 |
<para>The defmacro lambda-list keyword <literal>&environment</literal> may appear only at the |
| 57 |
top-level, first in the defmacro lambda-list if <literal>&whole</literal> is not supplied, |
| 58 |
or immediately after the variable that follows <literal>&whole</literal>, if <literal>&whole</literal> |
| 59 |
is supplied. <literal>&environment</literal> is not allowed within <replaceable>pseudo-var</replaceable>. Like |
| 60 |
<literal>&whole</literal>, use of <literal>&environment</literal> does not affect the processing of the |
| 61 |
rest of the defmacro lambda-list. If an <literal>&environment</literal> parameter is |
| 62 |
supplied and if this parameter is not used at all, then the &ECL; compiler |
| 63 |
will issue a warning. To suppress the warning, just remove the parameter from |
| 64 |
the defmacro lambda-list, or add an <literal>ignore</literal> declaration.</para> |
| 65 |
<para>The defmacro lambda-list keyword <literal>&body</literal> is completely equivalent to the |
| 66 |
&rest keyword. &ECL; takes no special action for <literal>&body</literal> parameters.</para> |
| 67 |
<para>Although useless, &ECL; allows supplied-p parameters to be destructured. |
| 68 |
This is useless because supplied-p parameters can never be bound to a non-empty |
| 69 |
list. Our intention is to stick to the specification in the |
| 70 |
&Steele84; as far as possible, even if it is silly to do so.</para> |
| 71 |
<para>Like for ordinary lambda-lists, the interpreter detects invalid arguments to |
| 72 |
macro expansion functions. When a parameter is destructured, the structure of |
| 73 |
the corresponding argument is also checked. Such runtime argument checking may |
| 74 |
or may not be embedded in compiled code, depending on the environment when the |
| 75 |
code was generated. If the code was generated while the <literal>safety</literal> optimize |
| 76 |
level is zero (that is, while the value of <literal>(proclamation '(optimize |
| 77 |
(safety 0)))</literal> is <replaceable>T</replaceable>), then the generated code does not perform argument |
| 78 |
checking at all. Otherwise, the compiled code does check the validity of |
| 79 |
arguments.</para> |
| 80 |
</chapter> |
| 81 |
<!-- Keep this comment at the end of the file |
| 82 |
Local variables: |
| 83 |
sgml-parent-document: "ecl.xml" |
| 84 |
sgml-indent-step: 1 |
| 85 |
nxml-child-indent: 1 |
| 86 |
nxml-outline-child-indent: 1 |
| 87 |
fill-column: 79 |
| 88 |
End: |
| 89 |
--></book> |