Debian Codegraph @

tutorial/macro_simple.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.1 Simple 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.1 Simple Macros</FONT><BR>
102
103
104
105 <P>The original "Hello World" program consisted of
106 a single macro definition.
107
108 <P>
109 <PRE>
110 @O@&lt;hello.txt@&gt;@{Hello World@+@}
111 </PRE>
112
113 <P>In fact, this is a rather exceptional macro, as it
114 causes its expansion to be written to a product file. The
115 <SAMP>@O</SAMP> (for <STRONG>O</STRONG>utput) signals this. In
116 FunnelWeb, most macros are defined using
117 <SAMP>@$</SAMP>. This results in a macro
118 that does not generate a product file, but which can be
119 called in other macros (including <SAMP>@O</SAMP> macros). Let
120 us expand the hello world program to include some other
121 macros.
122
123 <P>
124 <PRE>
125 @O@&lt;hello.txt@&gt;@{@&lt;Greetings@&gt;@+@}
126
127 @$@&lt;H@&gt;==@{Hello@}
128 @$@&lt;W@&gt;==@{World@}
129
130 @$@&lt;Greetings@&gt;==@{@&lt;H@&gt; @&lt;W@&gt;@}
131 </PRE>
132
133 <P>Type in the file and run it through FunnelWeb using the command:
134
135 <P>
136 <PRE>
137 fw hello
138 </PRE>
139
140 <P>The product file (result.out) should look like this:
141
142 <P>
143 <PRE>
144 Hello World
145 </PRE>
146
147 <P>This short program illustrates some of the features of
148 ordinary macros in FunnelWeb. Consider the <SAMP>@O</SAMP>
149 macro. Instead of containing straight text ("Hello
150 World"), it now contains the macro call
151 <SAMP>@&lt;Greetings@&gt;</SAMP>. A FunnelWeb macro can
152 be called from within the body of another macro just by
153 giving the macro name delimited in <SAMP>@&lt;</SAMP> and
154 <SAMP>@&gt;</SAMP>.
155
156 <P>At the bottom of the file is the definition of the
157 <SAMP>@&lt;Greetings@&gt;</SAMP> macro. The definition
158 is similar to the definition of <SAMP>hello.txt</SAMP> except
159 that it starts with <SAMP>@$</SAMP> to indicate that no
160 product file is desired from this macro (directly). It also
161 employs the optional <SAMP>==</SAMP> syntax which has no
162 semantic impact, but can be used to make definitions
163 clearer. The body of the
164 <SAMP>@&lt;Greetings@&gt;</SAMP> macro consists of
165 calls to the <SAMP>H</SAMP> and <SAMP>W</SAMP> macros which are
166 defined immediately above.
167
168 <P>Note that the macros are not constrained to be defined
169 in any particular order. One of the main features of
170 literate programming tools is that they allow the different
171 parts of the text document being developed (usually a
172 computer program) to be layed out in any
173 order. So
174 long as there is a definition somewhere in the input file
175 for every macro call, FunnelWeb will sort it all out.
176
177 <P>In fact, FunnelWeb's macro facility is very
178 simple. Unlike many macro
179 preprocessors which allow macros to define other macros,
180 FunnelWeb completely finishes parsing and analysing the
181 macros in the input file before it starts expanding them
182 into product files. Other preprocessors allow macros to be
183 redefined like variables (as in, say, TeX)
184 taking on many different values as the macro pre-processor
185 travels through the input file. In contrast, FunnelWeb has
186 no concept of "different times" and treats the input
187 as one huge static orderless, timeless, collection of
188 definitions. In FunnelWeb, there is only ever one time, and
189 so there can only ever be one value/definition for each
190 macro.
191
192
193 <P>
194 <TABLE WIDTH="100%">
195 <TR>
196 <TD ALIGN="left" VALIGN="bottom"><A HREF="macro.html"><IMG SRC="binary/fw_left.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Prev"></A></TD>
197 <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>
198 <TD ALIGN="right" VALIGN="bottom"><A HREF="macro_times.html"><IMG SRC="binary/fw_right.gif" HEIGHT="32" WIDTH="32" BORDER="0" ALT="Next"></A></TD>
199 </TR>
200 </TABLE>
201
202
203
204 <HR>
205 <FONT SIZE="2">
206 <A HREF="mailto:[email protected]">Webmaster</A>&nbsp;&nbsp;&nbsp;
207 <A HREF="copyright.html">Copyright &copy; Ross N. Williams 1992,1999. All rights reserved.</A><BR>
208 </FONT>
209
210 </FONT>
211 </TD>
212 </TR>
213 </TABLE>
214
215
216 </BODY>
217
218 <!-- *********************************************************************** -->
219 <!-- End Of A FunnelWeb Manual Web Page (www.ross.net/funnelweb/) -->
220 <!-- *********************************************************************** -->
221
222 </HTML>