4
***********************************************************************
5
FUNNELWEB MANUAL WEB PAGE
6
=========================
7
Copyright (c) Ross N. Williams 1992,1999. All rights reserved.
9
Permission is granted to redistribute and use this manual in
10
any medium, with or without modification, provided that all
11
notices (including, without limitation, the copyright
12
notice, this permission notice, any record of modification,
13
and all legal notices) are preserved on all copies, that all
14
modifications are clearly marked, and that modified versions
15
are not represented as the original version unless all the
16
modifications since the manual's original release by Ross N.
17
Williams (www.ross.net) consist of translations or other
18
transformations that alter only the manual's form, not its
19
content. THIS MANUAL IS PROVIDED "AS IS" AND WITHOUT ANY
20
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
21
LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
22
FITNESS FOR A PARTICULAR PURPOSE. TO THE EXTENT PERMITTED BY
23
LAW THERE IS ABSOLUTELY NO WARRANTY.
25
***********************************************************************
29
<TITLE>2.5 Parameterized Macros</TITLE>
30
<STYLE TYPE="text/css"> <!-- A {text-decoration: none} // --> </STYLE>
32
<BODY BACKGROUND="binary/background.gif"
41
<TD WIDTH="130" VALIGN="top">
42
<IMG SRC="binary/d_clear.gif" ALT="" WIDTH="130" HEIGHT="1"><BR>
47
<A HREF="http://www.ross.net/"
49
onClick="window.open('','rosshome','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
51
<IMG SRC="binary/rossnet_logo.gif"
52
WIDTH="64" HEIGHT="32"
53
BORDER="0" ALT="RossNet"
54
HSPACE="0" VSPACE="1"></A><BR>
57
<A HREF="../index.shtml"
59
onClick="window.open('','funnelweb','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
61
<IMG SRC="binary/linklogo.gif"
62
WIDTH="64" HEIGHT="32"
63
BORDER="0" ALT="FunnelWeb"
64
HSPACE="0" VSPACE="1"></A><BR>
66
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD BGCOLOR="#000000">
67
<A HREF="../reference/index.html"
68
TARGET="funnelwebreference"
69
onClick="window.open('','funnelwebreference','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
70
><FONT COLOR="#FFFFFF"><B>Reference</B></FONT></A><BR>
72
<A HREF="../developer/index.html"
73
TARGET="funnelwebdeveloper"
74
onClick="window.open('','funnelwebdeveloper','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
75
><FONT COLOR="#FFFFFF"><B>Developer</B></FONT></A><BR>
77
<A HREF="index.html"><FONT COLOR="#FFFFFF"><B>Tutorial</B></FONT></A><BR>
78
<A HREF="intro.html"><FONT COLOR="#FFFFFF">1 Introduction</FONT></A><BR>
79
<A HREF="macro.html"><FONT COLOR="#FFFFFF">2 Macros</FONT></A><BR>
80
<A HREF="type.html"><FONT COLOR="#FFFFFF">3 Typesetting</FONT></A><BR>
81
<A HREF="example.html"><FONT COLOR="#FFFFFF">4 Example</FONT></A><BR>
82
<A HREF="hints.html"><FONT COLOR="#FFFFFF">5 Hints</FONT></A><BR>
83
<A HREF="examples.html"><FONT COLOR="#FFFFFF">6 Examples</FONT></A><BR>
84
<A HREF="web.html"><FONT COLOR="#FFFFFF">7 Webmaking</FONT></A><BR>
87
<A HREF="search.html"><FONT COLOR="#FFFFFF"><B>SEARCH</B></FONT></A><BR>
93
<TD WIDTH="360" VALIGN="top">
97
<A HREF="../reference/index.html"><IMG SRC="binary/title.gif"
98
WIDTH="302" HEIGHT="24"
99
BORDER="0" ALT="FunnelWeb Tutorial Manual"
100
HSPACE="0" VSPACE="0"></A>
101
<P><FONT SIZE="5">2.5 Parameterized Macros</FONT><BR>
105
<P>No self-respecting macro preprocessor would be complete
106
without some form of macro parameterization, and FunnelWeb
107
is no exception. FunnelWeb allows each macro to have from
108
zero to nine formal parameters
109
named <SAMP>@1</SAMP>, <SAMP>@2</SAMP>,
110
<SAMP>@3</SAMP>, <SAMP>@4</SAMP>, <SAMP>@5</SAMP>, <SAMP>@6</SAMP>,
111
<SAMP>@7</SAMP>, <SAMP>@8</SAMP>, and <SAMP>@9</SAMP>.
113
<P>To define a macro with one or more parameters, insert a
114
formal parameter list just after
115
the macro name in the macro definition. Because macro
116
parameters have fixed names
117
(<SAMP>@1</SAMP>...<SAMP>@9</SAMP>), there is no need to
118
specify the names of formal parameters in the formal
119
parameter list. All that need be conveyed is how many
120
parameters the macro has. Here is an example of the
121
definition of a macro having three parameters:
125
@$@<While loop@>@(@3@)@M==@{@-
134
<P>To call a parameterized macro, an actual
135
parameter list must be supplied
136
that contains exactly the same number of actual parameters
137
as there are formal parameters in the definition of the
138
macro being called. An actual parameter list is delimited by
139
<SAMP>@(</SAMP> and <SAMP>@)</SAMP>, and
140
parameters are <I>separated</I> by
141
<SAMP>@,</SAMP>. The actual parameters themselves
142
are general FunnelWeb expressions (see the
143
<A HREF="../reference/index.html"
144
TARGET="funnelwebreference"
145
onClick="window.open('','funnelwebreference','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
146
>FunnelWeb Reference Manual</A> for the exact syntax) and can
147
be inserted into the list directly or can be delimited by
148
<SAMP>@"</SAMP> so as to allow some white space to
149
assist in formatting the actual parameters. Here are some
150
examples of calls of the <SAMP>While loop</SAMP> macro defined
155
@! First form of actual parameters
156
@! without whitespace and double quotes.
157
@<While loop@>@(@-
158
x=1;@,x<=10@,printf("X=%u\n",x);@)
160
@! Second form of actual parameters. The double
161
@! quotes allow non-active whitespace that helps
162
@! to lay out the actual parameters neatly. This
163
@! call is functionally identical to the one above.
164
@<While loop@>@(
167
@"printf("X=%u\n",x);@" @)
169
@! The two forms can be mixed in a single call.
170
@<While loop@>@(x=1;@,x<=10@,
171
@"printf("X=%u\n",x);@" @)
174
<P>A few rules about parameterized macros are worth
175
mentioning. Macros that do not have any parameters must have
176
no formal or actual parameter lists. Additive macros can have parameters, but the
177
formal parameter list must appear in the first definition
180
<P>Here is another example of the use of parameterized
181
macros. This time, parameters and macro calls are used in a
182
FunnelWeb input file that constructs an O(n)
183
representation of a song whose full size is O(n^2) in the number n of
188
@O@<Twelve_bugs.txt@>==@{@-
189
The Twelve Bugs of Christmas
190
----------------------------
191
@<Verse@>@(@"first@" @,@<1@>@)
192
@<Verse@>@(@"second@" @,@<2@>@)
193
@<Verse@>@(@"third@" @,@<3@>@)
194
@<Verse@>@(@"fourth@" @,@<4@>@)
195
@<Verse@>@(@"fifth@" @,@<5@>@)
196
@<Verse@>@(@"sixth@" @,@<6@>@)
197
@<Verse@>@(@"seventh@" @,@<7@>@)
198
@<Verse@>@(@"eighth@" @,@<8@>@)
199
@<Verse@>@(@"ninth@" @,@<9@>@)
200
@<Verse@>@(@"tenth@" @,@<A@>@)
201
@<Verse@>@(@"eleventh@" @,@<B@>@)
202
@<Verse@>@(@"twelfth@" @,@<C@>@)
204
This song appeared in the internet newsgroup
205
rec.humor.funny on 24-Dec-1991. It was contributed
206
by Pat Scannell (scannell@@darkstar.ma30.bull.com).
209
@$@<Verse@>@(@2@)@M==@{@-
210
For the @1 bug of Christmas, my manager said to me
214
@$@<1@>@M==@{@-
215
See if they can do it again.@}
216
@$@<2@>@M==@{@-
217
Ask them how they did it and@+@<1@>@}
218
@$@<3@>@M==@{@-
219
Try to reproduce it@+@<2@>@}
220
@$@<4@>@M==@{@-
221
Run with the debugger@+@<3@>@}
222
@$@<5@>@M==@{@-
223
Ask for a dump@+@<4@>@}
224
@$@<6@>@M==@{@-
225
Reinstall the software@+@<5@>@}
226
@$@<7@>@M==@{@-
227
Say they need an upgrade@+@<6@>@}
228
@$@<8@>@M==@{@-
229
Find a way around it@+@<7@>@}
230
@$@<9@>@M==@{@-
231
Blame it on the hardware@+@<8@>@}
232
@$@<A@>@M==@{@-
233
Change the documentation@+@<9@>@}
234
@$@<B@>@M==@{@-
235
Say it's not supported@+@<A@>@}
236
@$@<C@>@M==@{@-
237
Tell them it's a feature@+@<B@>@}
244
<TD ALIGN="left" VALIGN="bottom"><A HREF="macro_additive.html"><IMG SRC="binary/fw_left.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Prev"></A></TD>
245
<TD ALIGN="center" VALIGN="bottom"><A HREF="macro.html"><IMG SRC="binary/fw_up.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Up"></A></TD>
246
<TD ALIGN="right" VALIGN="bottom"><A HREF="macro_library.html"><IMG SRC="binary/fw_right.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Next"></A></TD>
254
<A HREF="mailto:webmaster@ross.net">Webmaster</A>
255
<A HREF="copyright.html">Copyright © Ross N. Williams 1992,1999. All rights reserved.</A><BR>
266
<!-- *********************************************************************** -->
267
<!-- End Of A FunnelWeb Manual Web Page (www.ross.net/funnelweb/) -->
268
<!-- *********************************************************************** -->