~ubuntu-branches/ubuntu/gutsy/funnelweb-doc/gutsy

« back to all changes in this revision

Viewing changes to tutorial/macro_additive.html

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2002-03-28 23:21:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020328232107-3d1jiqv1eqmco3j9
Tags: upstream-3.2d
ImportĀ upstreamĀ versionĀ 3.2d

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.4 Additive 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.4 Additive Macros</FONT><BR>
 
102
 
 
103
 
 
104
 
 
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
 
109
except that
 
110
 
 
111
<P>
 
112
<OL>
 
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.
 
117
</OL>
 
118
 
 
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
 
124
explicitly.
 
125
 
 
126
<P>
 
127
<PRE>
 
128
@!******************************
 
129
 
 
130
@O@&lt;prog.pas@&gt;==@{@-
 
131
program adt(input,output);
 
132
@&lt;Types@&gt;
 
133
@&lt;Variables@&gt;
 
134
@&lt;Procedures@&gt;
 
135
begin startproc; end.
 
136
@}
 
137
 
 
138
@!******************************
 
139
 
 
140
@$@&lt;Types@&gt;+=@{@-
 
141
type buffer_type =
 
142
   record
 
143
   length : integer;
 
144
   buf : array[1..100] of char;
 
145
   end;
 
146
@}
 
147
 
 
148
@$@&lt;Variables@&gt;+=@{@-
 
149
bigbuf : buffer_type;
 
150
@}
 
151
 
 
152
@$@&lt;Procedures@&gt;+=@{@-
 
153
procedure buf_init (var b : buffer_type               )
 
154
   {Body of buf_init}
 
155
procedure buf_add  (var b : buffer_type;     ch : char)
 
156
   {Body of buf_add}
 
157
procedure buf_get  (var b : buffer_type; var ch : char)
 
158
   {Body of buf_get}
 
159
@}
 
160
 
 
161
@!******************************
 
162
 
 
163
@$@&lt;Types@&gt;+=@{@-
 
164
type complex_type = record r,i : real; end;
 
165
@}
 
166
 
 
167
@$@&lt;Procedures@&gt;+=@{@-
 
168
procedure cm_set (var c: complex_type; a,b: real)
 
169
   {Body of cm_set}
 
170
procedure cm_add (a,b: complex_type; var c: complex_type)
 
171
   {Body of cm_add}
 
172
{Other procedures and functions}
 
173
@}
 
174
 
 
175
@!******************************
 
176
 
 
177
{...more pieces of program...}
 
178
 
 
179
@!******************************
 
180
</PRE>
 
181
 
 
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.
 
188
 
 
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.
 
201
 
 
202
<P>
 
203
<PRE>
 
204
@!******************************
 
205
 
 
206
@O@&lt;prog.pas@&gt;==@{@-
 
207
program adt(input,output);
 
208
@&lt;Types@&gt;
 
209
@&lt;Variables@&gt;
 
210
@&lt;Procedures@&gt;
 
211
begin startproc; end.
 
212
@}
 
213
 
 
214
@$@&lt;Types@&gt;==@{@-
 
215
@&lt;Buffer type@&gt;
 
216
@&lt;Complex type@&gt;
 
217
@}
 
218
 
 
219
@$@&lt;Variables@&gt;==@{@-
 
220
@&lt;Buffer variable@&gt;
 
221
@}
 
222
 
 
223
@$@&lt;Procedures@&gt;==@{@-
 
224
@&lt;Buffer procedures@&gt;
 
225
@&lt;Complex procedures@&gt;
 
226
@}
 
227
 
 
228
@!******************************
 
229
 
 
230
@$@&lt;Buffer type@&gt;==@{@-
 
231
type buffer_type = record
 
232
                   length : integer;
 
233
                   buf : array[1..100] of char;
 
234
                   end;
 
235
@}
 
236
 
 
237
@$@&lt;Buffer variable@&gt;==@{@-
 
238
bigbuf : buffer_type;
 
239
@}
 
240
 
 
241
@$@&lt;Buffer procedures@&gt;==@{@-
 
242
procedure buf_init(var b : buffer_type)
 
243
   {Body of buf_init}
 
244
procedure buf_add(var b : buffer_type; ch : char)
 
245
   {Body of buf_add}
 
246
procedure buf_get(var b : buffer_type; var ch : char)
 
247
   {Body of buf_get}
 
248
@}
 
249
 
 
250
@!******************************
 
251
 
 
252
@$@&lt;Complex type@&gt;==@{@-
 
253
type complex_type = record r,i : real; end;
 
254
@}
 
255
 
 
256
@$@&lt;Complex procedures@&gt;+=@{@-
 
257
procedure cm_set(var c: complex_type; a,b : real)
 
258
   {Body of cm_set}
 
259
procedure cm_add(a,b : complex_type; var c: complex_type)
 
260
   {Body of cm_add}
 
261
{Other procedures and functions}
 
262
@}
 
263
 
 
264
@!******************************
 
265
 
 
266
{...more pieces of program...}
 
267
 
 
268
@!******************************
 
269
</PRE>
 
270
 
 
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.
 
277
 
 
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
 
282
product files.
 
283
 
 
284
 
 
285
<P>
 
286
<TABLE WIDTH="100%">
 
287
<TR>
 
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>
 
291
</TR>
 
292
</TABLE>
 
293
 
 
294
 
 
295
 
 
296
<HR>
 
297
<FONT SIZE="2">
 
298
<A HREF="mailto:webmaster@ross.net">Webmaster</A>&nbsp;&nbsp;&nbsp;
 
299
<A HREF="copyright.html">Copyright &copy; Ross N. Williams 1992,1999. All rights reserved.</A><BR>
 
300
</FONT>
 
301
 
 
302
</FONT>
 
303
</TD>
 
304
</TR>
 
305
</TABLE>
 
306
 
 
307
 
 
308
</BODY>
 
309
 
 
310
<!-- *********************************************************************** -->
 
311
<!--      End Of A FunnelWeb Manual Web Page (www.ross.net/funnelweb/)       -->
 
312
<!-- *********************************************************************** -->
 
313
 
 
314
</HTML>