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.4 Additive 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.4 Additive Macros</FONT><BR>
105
<P>Sometimes it is convenient to build up the definition
106
of a macro in stages throughout the input file. In
107
FunnelWeb, this can be done using an <STRONG>additive
108
macro</STRONG>. An additive macro is identical to an ordinary macro
113
<LI> It has <SAMP>+=</SAMP> instead of <SAMP>==</SAMP>.
114
<LI> It can be defined in one or more parts throughout the input file.
115
The definition of the macro is the concatenation of all the parts in the
116
order in which they appear.
119
<P>The following example shows how additive macros can be
120
used to scatter and regroup information, in this case
121
assisting in the lucid construction of a data
122
abstraction in a language
123
(Pascal) that does not support them
128
@!******************************
130
@O@<prog.pas@>==@{@-
131
program adt(input,output);
135
begin startproc; end.
138
@!******************************
140
@$@<Types@>+=@{@-
144
buf : array[1..100] of char;
148
@$@<Variables@>+=@{@-
149
bigbuf : buffer_type;
152
@$@<Procedures@>+=@{@-
153
procedure buf_init (var b : buffer_type )
155
procedure buf_add (var b : buffer_type; ch : char)
157
procedure buf_get (var b : buffer_type; var ch : char)
161
@!******************************
163
@$@<Types@>+=@{@-
164
type complex_type = record r,i : real; end;
167
@$@<Procedures@>+=@{@-
168
procedure cm_set (var c: complex_type; a,b: real)
170
procedure cm_add (a,b: complex_type; var c: complex_type)
172
{Other procedures and functions}
175
@!******************************
177
{...more pieces of program...}
179
@!******************************
182
<P>It is important to remember that the definition of each
183
macro does not change throughout the input file. FunnelWeb
184
parses the entire input file and assembles all the macro
185
definitions before it even starts to expand macros. As a
186
result, each additive macro can only have one definition,
187
and that definition is the concatenation of all its parts.
189
<P>The example above shows how additive macros can be used
190
to rearrange the presentation of a computer program in the
191
order in which the user wishes to discuss it rather than the
192
order in which the compiler requires that it be consumed. It
193
is easy, however, to abuse the feature of additive macros.
194
In many cases, the same effect can be obtained more clearly
195
by replacing each part of an additive macro in-situ using
196
uniquely named non-additive macros, and then collect them
197
together as a group at the point where the additive macro is
198
called. Doing this is more work, and is more error prone,
199
but can result in a clearer exposition. The following
200
program illustrates this alternative approach.
204
@!******************************
206
@O@<prog.pas@>==@{@-
207
program adt(input,output);
211
begin startproc; end.
214
@$@<Types@>==@{@-
215
@<Buffer type@>
216
@<Complex type@>
219
@$@<Variables@>==@{@-
220
@<Buffer variable@>
223
@$@<Procedures@>==@{@-
224
@<Buffer procedures@>
225
@<Complex procedures@>
228
@!******************************
230
@$@<Buffer type@>==@{@-
231
type buffer_type = record
233
buf : array[1..100] of char;
237
@$@<Buffer variable@>==@{@-
238
bigbuf : buffer_type;
241
@$@<Buffer procedures@>==@{@-
242
procedure buf_init(var b : buffer_type)
244
procedure buf_add(var b : buffer_type; ch : char)
246
procedure buf_get(var b : buffer_type; var ch : char)
250
@!******************************
252
@$@<Complex type@>==@{@-
253
type complex_type = record r,i : real; end;
256
@$@<Complex procedures@>+=@{@-
257
procedure cm_set(var c: complex_type; a,b : real)
259
procedure cm_add(a,b : complex_type; var c: complex_type)
261
{Other procedures and functions}
264
@!******************************
266
{...more pieces of program...}
268
@!******************************
271
<P>One of advantages of FunnelWeb (and literate
272
programming in general) is that (as shown above) it allows
273
the user to lay out the program in whatever order is
274
desired with near total
275
independence from the ordering requirements of the target
276
programming language.
278
<P>Additive macros are allowed to be tagged with
279
<SAMP>@Z</SAMP> and <SAMP>@M</SAMP> just as other macros can,
280
but the tags must appear only on the first definition of the
281
macro. Additive macros cannot be connected directly to
288
<TD ALIGN="left" VALIGN="bottom"><A HREF="macro_indent.html"><IMG SRC="binary/fw_left.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Prev"></A></TD>
289
<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>
290
<TD ALIGN="right" VALIGN="bottom"><A HREF="macro_param.html"><IMG SRC="binary/fw_right.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Next"></A></TD>
298
<A HREF="mailto:webmaster@ross.net">Webmaster</A>
299
<A HREF="copyright.html">Copyright © Ross N. Williams 1992,1999. All rights reserved.</A><BR>
310
<!-- *********************************************************************** -->
311
<!-- End Of A FunnelWeb Manual Web Page (www.ross.net/funnelweb/) -->
312
<!-- *********************************************************************** -->