Debian Codegraph @

tutorial/macro_param.html

raw symbols SCIP
1
2 <HTML>
3 <!--
4 ***********************************************************************
5 FUNNELWEB MANUAL WEB PAGE
6 =========================
7 Copyright (c) Ross N. Williams 1992,1999. All rights reserved.
8
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.
24
25 ***********************************************************************
26 -->
27
28 <HEAD>
29 <TITLE>2.5 Parameterized Macros</TITLE>
30 <STYLE TYPE="text/css"> <!-- A {text-decoration: none} // --> </STYLE>
31 </HEAD>
32 <BODY BACKGROUND="binary/background.gif"
33 BGCOLOR="#FFFFFF"
34 TEXT="#000000"
35 VLINK="#660000"
36 LINK="#FF0000"
37 ALINK="#CC0000">
38
39 <TABLE WIDTH="490">
40 <TR>
41 <TD WIDTH="130" VALIGN="top">
42 <IMG SRC="binary/d_clear.gif" ALT="" WIDTH="130" HEIGHT="1"><BR>
43
44 <FONT SIZE="2">
45 <BR>
46
47 <A HREF="http://www.ross.net/"
48 TARGET="rosshome"
49 onClick="window.open('','rosshome','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
50 >
51 <IMG SRC="binary/rossnet_logo.gif"
52 WIDTH="64" HEIGHT="32"
53 BORDER="0" ALT="RossNet"
54 HSPACE="0" VSPACE="1"></A><BR>
55 <BR>
56
57 <A HREF="../index.shtml"
58 TARGET="funnelweb"
59 onClick="window.open('','funnelweb','location,status,menubar,scrollbars,resizable',false).focus(); return true;"
60 >
61 <IMG SRC="binary/linklogo.gif"
62 WIDTH="64" HEIGHT="32"
63 BORDER="0" ALT="FunnelWeb"
64 HSPACE="0" VSPACE="1"></A><BR>
65 <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>
71 <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>
76 <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>
85
86 <BR>
87 <A HREF="search.html"><FONT COLOR="#FFFFFF"><B>SEARCH</B></FONT></A><BR>
88 </FONT>
89 </TD></TR></TABLE>
90
91
92 </TD>
93 <TD WIDTH="360" VALIGN="top">
94 <FONT SIZE="3">
95
96
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>
102
103
104
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>.
112
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:
122
123 <P>
124 <PRE>
125 @$@&lt;While loop@&gt;@(@3@)@M==@{@-
126 @1
127 while (@2)
128 {
129 @3
130 }
131 @}
132 </PRE>
133
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>&nbsp; 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
151 above.
152
153 <P>
154 <PRE>
155 @! First form of actual parameters
156 @! without whitespace and double quotes.
157 @&lt;While loop@&gt;@(@-
158 x=1;@,x&lt;=10@,printf("X=%u\n",x);@)
159
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 @&lt;While loop@&gt;@(
165 @"x:=1;@" @,
166 @"x&lt;=10@" @,
167 @"printf("X=%u\n",x);@" @)
168
169 @! The two forms can be mixed in a single call.
170 @&lt;While loop@&gt;@(x=1;@,x&lt;=10@,
171 @"printf("X=%u\n",x);@" @)
172 </PRE>
173
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
178 part only.
179
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
184 unique lines.
185
186 <P>
187 <PRE>
188 @O@&lt;Twelve_bugs.txt@&gt;==@{@-
189 The Twelve Bugs of Christmas
190 ----------------------------
191 @&lt;Verse@&gt;@(@"first@" @,@&lt;1@&gt;@)
192 @&lt;Verse@&gt;@(@"second@" @,@&lt;2@&gt;@)
193 @&lt;Verse@&gt;@(@"third@" @,@&lt;3@&gt;@)
194 @&lt;Verse@&gt;@(@"fourth@" @,@&lt;4@&gt;@)
195 @&lt;Verse@&gt;@(@"fifth@" @,@&lt;5@&gt;@)
196 @&lt;Verse@&gt;@(@"sixth@" @,@&lt;6@&gt;@)
197 @&lt;Verse@&gt;@(@"seventh@" @,@&lt;7@&gt;@)
198 @&lt;Verse@&gt;@(@"eighth@" @,@&lt;8@&gt;@)
199 @&lt;Verse@&gt;@(@"ninth@" @,@&lt;9@&gt;@)
200 @&lt;Verse@&gt;@(@"tenth@" @,@&lt;A@&gt;@)
201 @&lt;Verse@&gt;@(@"eleventh@" @,@&lt;B@&gt;@)
202 @&lt;Verse@&gt;@(@"twelfth@" @,@&lt;C@&gt;@)
203
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).
207 @}
208
209 @$@&lt;Verse@&gt;@(@2@)@M==@{@-
210 For the @1 bug of Christmas, my manager said to me
211 @2
212 @}
213
214 @$@&lt;1@&gt;@M==@{@-
215 See if they can do it again.@}
216 @$@&lt;2@&gt;@M==@{@-
217 Ask them how they did it and@+@&lt;1@&gt;@}
218 @$@&lt;3@&gt;@M==@{@-
219 Try to reproduce it@+@&lt;2@&gt;@}
220 @$@&lt;4@&gt;@M==@{@-
221 Run with the debugger@+@&lt;3@&gt;@}
222 @$@&lt;5@&gt;@M==@{@-
223 Ask for a dump@+@&lt;4@&gt;@}
224 @$@&lt;6@&gt;@M==@{@-
225 Reinstall the software@+@&lt;5@&gt;@}
226 @$@&lt;7@&gt;@M==@{@-
227 Say they need an upgrade@+@&lt;6@&gt;@}
228 @$@&lt;8@&gt;@M==@{@-
229 Find a way around it@+@&lt;7@&gt;@}
230 @$@&lt;9@&gt;@M==@{@-
231 Blame it on the hardware@+@&lt;8@&gt;@}
232 @$@&lt;A@&gt;@M==@{@-
233 Change the documentation@+@&lt;9@&gt;@}
234 @$@&lt;B@&gt;@M==@{@-
235 Say it's not supported@+@&lt;A@&gt;@}
236 @$@&lt;C@&gt;@M==@{@-
237 Tell them it's a feature@+@&lt;B@&gt;@}
238 </PRE>
239
240
241 <P>
242 <TABLE WIDTH="100%">
243 <TR>
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>
247 </TR>
248 </TABLE>
249
250
251
252 <HR>
253 <FONT SIZE="2">
254 <A HREF="mailto:[email protected]">Webmaster</A>&nbsp;&nbsp;&nbsp;
255 <A HREF="copyright.html">Copyright &copy; Ross N. Williams 1992,1999. All rights reserved.</A><BR>
256 </FONT>
257
258 </FONT>
259 </TD>
260 </TR>
261 </TABLE>
262
263
264 </BODY>
265
266 <!-- *********************************************************************** -->
267 <!-- End Of A FunnelWeb Manual Web Page (www.ross.net/funnelweb/) -->
268 <!-- *********************************************************************** -->
269
270 </HTML>