<!-- 95% W3C COMPLIANT, 95% CSS FREE, RAW HTML --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> <title>BiglooA ``practical Scheme compiler''User manual for version 3.2bJune 2009</title> <style type="text/css"> <!-- pre { font-family: monospace } tt { font-family: monospace } code { font-family: monospace } p.flushright { text-align: right } p.flushleft { text-align: left } span.sc { font-variant: small-caps } span.sf { font-family: sans-serif } span.skribetitle { font-family: sans-serif; font-weight: bolder; font-size: x-large; } span.refscreen { } span.refprint { display: none; } --> </style> </head> <body class="chapter" bgcolor="#ffffff"> <table width="100%" class="skribetitle" cellspacing="0" cellpadding="0"><tbody> <tr><td align="center" bgcolor="#8381de"><div class="skribetitle"><strong><big><big><big>3. Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009 -- Modules</big></big></big></strong></div><center> </center> </td></tr></tbody></table> <table cellpadding="3" cellspacing="0" width="100%" class="skribe-margins"><tr> <td align="left" valign="top" class="skribe-left-margin" width="20%" bgcolor="#dedeff"><div class="skribe-left-margin"> <br/><center id='center25952' ><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody> <tr bgcolor="#8381de"><th id="tc25942" align="center" colspan="1"><font color="#ffffff"><strong id='bold25940' >main page</strong></font></th></tr> <tr bgcolor="#ffffff"><td id="tc25949" align="center" colspan="1"><table width="100%" border="0" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc25945" align="left" valign="top" colspan="1"><strong id='bold25944' >top:</strong></td><td id="tc25946" align="right" valign="top" colspan="1"><a href="bigloo.html#Bigloo-A-``practical-Scheme-compiler''-User-manual-for-version-3.2b-June-2009" class="inbound">Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009</a></td></tr> </tbody></table> </td></tr> </tbody></table> </center> <br/><br/><center id='center25962' ><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody> <tr bgcolor="#8381de"><th id="tc25956" align="center" colspan="1"><font color="#ffffff"><strong id='bold25954' >Modules</strong></font></th></tr> <tr bgcolor="#ffffff"><td id="tc25959" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc"> <tbody> <tr><td valign="top" align="left">3.1</td><td colspan="4" width="100%"><a href="bigloo-4.html#Program-Structure">Program Structure</a></td></tr> <tr><td valign="top" align="left">3.2</td><td colspan="4" width="100%"><a href="bigloo-4.html#Module-declaration">Module declaration</a></td></tr> <tr><td valign="top" align="left">3.3</td><td colspan="4" width="100%"><a href="bigloo-4.html#Module-initialization">Module initialization</a></td></tr> <tr><td valign="top" align="left">3.4</td><td colspan="4" width="100%"><a href="bigloo-4.html#Qualified-notation">Qualified notation</a></td></tr> <tr><td valign="top" align="left">3.5</td><td colspan="4" width="100%"><a href="bigloo-4.html#Inline-procedures">Inline procedures</a></td></tr> <tr><td valign="top" align="left">3.6</td><td colspan="4" width="100%"><a href="bigloo-4.html#Module-access-file">Module access file</a></td></tr> <tr><td valign="top" align="left">3.7</td><td colspan="4" width="100%"><a href="bigloo-4.html#Reading-path">Reading path</a></td></tr> </tbody> </table> </td></tr> </tbody></table> </center> <br/><br/><center id='center25972' ><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody> <tr bgcolor="#8381de"><th id="tc25966" align="center" colspan="1"><font color="#ffffff"><strong id='bold25964' >Chapters</strong></font></th></tr> <tr bgcolor="#ffffff"><td id="tc25969" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc"> <tbody> <tr><td valign="top" align="left"></td><td colspan="4" width="100%"><a href="bigloo-1.html#Acknowledgements">Acknowledgements</a></td></tr> <tr><td valign="top" align="left">1</td><td colspan="4" width="100%"><a href="bigloo-2.html#Table-of-contents">Table of contents</a></td></tr> <tr><td valign="top" align="left">2</td><td colspan="4" width="100%"><a href="bigloo-3.html#Overview-of-Bigloo">Overview of Bigloo</a></td></tr> <tr><td valign="top" align="left">3</td><td colspan="4" width="100%"><a href="bigloo-4.html#Modules">Modules</a></td></tr> <tr><td valign="top" align="left">4</td><td colspan="4" width="100%"><a href="bigloo-5.html#Core-Language">Core Language</a></td></tr> <tr><td valign="top" align="left">5</td><td colspan="4" width="100%"><a href="bigloo-6.html#DSSSL-support">DSSSL support</a></td></tr> <tr><td valign="top" align="left">6</td><td colspan="4" width="100%"><a href="bigloo-7.html#Standard-Library">Standard Library</a></td></tr> <tr><td valign="top" align="left">7</td><td colspan="4" width="100%"><a href="bigloo-8.html#Pattern-Matching">Pattern Matching</a></td></tr> <tr><td valign="top" align="left">8</td><td colspan="4" width="100%"><a href="bigloo-9.html#Fast-search">Fast search</a></td></tr> <tr><td valign="top" align="left">9</td><td colspan="4" width="100%"><a href="bigloo-10.html#Structures-and-Records">Structures and Records</a></td></tr> <tr><td valign="top" align="left">10</td><td colspan="4" width="100%"><a href="bigloo-11.html#Object-System">Object System</a></td></tr> <tr><td valign="top" align="left">11</td><td colspan="4" width="100%"><a href="bigloo-12.html#Regular-parsing">Regular parsing</a></td></tr> <tr><td valign="top" align="left">12</td><td colspan="4" width="100%"><a href="bigloo-13.html#Lalr(1)-parsing">Lalr(1) parsing</a></td></tr> <tr><td valign="top" align="left">13</td><td colspan="4" width="100%"><a href="bigloo-14.html#Posix-Regular-Expressions">Posix Regular Expressions</a></td></tr> <tr><td valign="top" align="left">14</td><td colspan="4" width="100%"><a href="bigloo-15.html#Command-Line-Parsing">Command Line Parsing</a></td></tr> <tr><td valign="top" align="left">15</td><td colspan="4" width="100%"><a href="bigloo-16.html#Cryptography">Cryptography</a></td></tr> <tr><td valign="top" align="left">16</td><td colspan="4" width="100%"><a href="bigloo-17.html#Errors-Assertions-and-Traces">Errors, Assertions, and Traces</a></td></tr> <tr><td valign="top" align="left">17</td><td colspan="4" width="100%"><a href="bigloo-18.html#Threads">Threads</a></td></tr> <tr><td valign="top" align="left">18</td><td colspan="4" width="100%"><a href="bigloo-19.html#Database-library">Database library</a></td></tr> <tr><td valign="top" align="left">19</td><td colspan="4" width="100%"><a href="bigloo-20.html#Multimedia-library">Multimedia library</a></td></tr> <tr><td valign="top" align="left">20</td><td colspan="4" width="100%"><a href="bigloo-21.html#Mail-library">Mail library</a></td></tr> <tr><td valign="top" align="left">21</td><td colspan="4" width="100%"><a href="bigloo-22.html#Eval-and-code-interpretation">Eval and code interpretation</a></td></tr> <tr><td valign="top" align="left">22</td><td colspan="4" width="100%"><a href="bigloo-23.html#Macro-expansion">Macro expansion</a></td></tr> <tr><td valign="top" align="left">23</td><td colspan="4" width="100%"><a href="bigloo-24.html#Parameters">Parameters</a></td></tr> <tr><td valign="top" align="left">24</td><td colspan="4" width="100%"><a href="bigloo-25.html#Explicit-typing">Explicit typing</a></td></tr> <tr><td valign="top" align="left">25</td><td colspan="4" width="100%"><a href="bigloo-26.html#The-C-interface">The C interface</a></td></tr> <tr><td valign="top" align="left">26</td><td colspan="4" width="100%"><a href="bigloo-27.html#The-Java-interface">The Java interface</a></td></tr> <tr><td valign="top" align="left">27</td><td colspan="4" width="100%"><a href="bigloo-28.html#Bigloo-Libraries">Bigloo Libraries</a></td></tr> <tr><td valign="top" align="left">28</td><td colspan="4" width="100%"><a href="bigloo-29.html#Extending-the-Runtime-System">Extending the Runtime System</a></td></tr> <tr><td valign="top" align="left">29</td><td colspan="4" width="100%"><a href="bigloo-30.html#SRFIs">SRFIs</a></td></tr> <tr><td valign="top" align="left">30</td><td colspan="4" width="100%"><a href="bigloo-31.html#Compiler-description">Compiler description</a></td></tr> <tr><td valign="top" align="left">31</td><td colspan="4" width="100%"><a href="bigloo-32.html#User-Extensions">User Extensions</a></td></tr> <tr><td valign="top" align="left">32</td><td colspan="4" width="100%"><a href="bigloo-33.html#Bigloo-Development-Environment">Bigloo Development Environment</a></td></tr> <tr><td valign="top" align="left">33</td><td colspan="4" width="100%"><a href="bigloo-34.html#Global-Index">Global Index</a></td></tr> <tr><td valign="top" align="left">34</td><td colspan="4" width="100%"><a href="bigloo-35.html#Library-Index">Library Index</a></td></tr> <tr><td valign="top" align="left"></td><td colspan="4" width="100%"><a href="bigloo-36.html#Bibliography">Bibliography</a></td></tr> </tbody> </table> </td></tr> </tbody></table> </center> </div></td> <td align="left" valign="top" class="skribe-body"><div class="skribe-body"> <a name="Modules" class="mark"></a><a name="g1183" class="mark"></a> A modules is a compiler and interpreter entity. Modules have been first designed for the compiler that compiles modules and then, links them against libraries in order to produce executables. A module may be split into several files but a file cannot contain more than <em id='emph1185' >one</em> module. A module is made of a module clause that is a list for which the <code id='code1186' >car</code> is the symbol <code id='code1187' >module</code> and followed by any Bigloo expression (that is definitions or expressions). The module clause names the module and defines the scope of the definitions. At last, the module clause is also the place where foreign bindings are defined and where classes are defined. Recent versions of Bigloo (since 2.7b) fully supports modules from the interpreter.<br/><br/> <!-- Program Structure --> <a name="Program-Structure"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">3.1 Program Structure</font> </h3></td></tr></table> </div><div class="section"> <a name="Program-Structure" class="mark"></a><a name="g1189" class="mark"></a> A Bigloo program is composed of one or more Bigloo modules where a module is defined by the following grammar:<br/><br/><center id='center1194' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ccccff"><pre class="prog" id='prog1192' ><module> ==> <module-declaration> <module-body> <module-declaration> ==> the module declaration <module-body> ==> the module body </pre> </td></tr> </tbody></table></center> A module is not related to a specific file and can be spread over several files if that is convenient. In particular, there is no relationship between module names and file names. The module declaration (see <a href="bigloo-4.html#Module-Declaration" class="inbound">Module Declaration</a>) must be the first expression in the first of the files containing the module; other expressions form the body of the module. The module body (see <a href="bigloo-5.html#Core-Language" class="inbound">Core Language</a>) contains global variables, function definitions and <em id='emph1195' >top level</em> expressions (see <a href="bigloo-5.html#Expressions" class="inbound">Expressions</a>).<br/><br/></div><br> <!-- Module declaration --> <a name="Module-declaration"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">3.2 Module declaration</font> </h3></td></tr></table> </div><div class="section"> <a name="Module-Declaration" class="mark"></a><a name="g1197" class="mark"></a> The module declaration form is<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1201" class="mark"></a><a name="module" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1205" align="left" colspan="1"><strong id='bold1203' >module</strong><em id='it1204' > name clause ...</em></td><td id="tc1206" align="right" colspan="1">bigloo syntax</td></tr> </tbody></table> This form defines a module and must be the first in the file. The argument <code id='code1210' ><em id='it1209' >name</em></code> is a symbol naming the module. If the same module name is used more than once, Bigloo signals an error. The runtime library is composed of modules that are read when a user module is compiled and hence, if a user module has the same name as one of the library modules, an error is signaled.<br/><br/>A simple module can be:<br/><br/><center id='center1219' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1217' >(<font color="#1919af"><strong id='bold25973' >module</strong></font> <font color="#1919af"><strong id='bold25975' >foo</strong></font>)<br/><br/>(display <font color="red">"this is a module"</font>) </pre> </td></tr> </tbody></table></center> The first line here is the complete module definition, the last line is the complete module body and together they form a complete Bigloo program. If these lines were stored in file <code id='code1220' >zz.scm</code>, invoking <samp id='samp1221' >bigloo zz.scm</samp> would create the executable <code id='code1222' >a.out</code> which, when obeyed, would display <samp id='samp1223' >this is a module</samp> on the terminal.<br/><br/><em id='emph1225' >Note:</em> Some special identifiers are reserved and can't be used to name modules. If such an identifier is used, the compiler will produce the message:<br/><br/><center id='center1234' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1232' >#(<font color="#1919af"><strong id='bold25978' >module</strong></font> <font color="#1919af"><strong id='bold25980' >t</strong></font> #^ # *** ERROR<strong id='bold25982' >:bigloo</strong><strong id='bold25984' >:TOP-LEVEL</strong><strong id='bold25986' >:Parse</strong> error # Illegal module name -- (MODULE eval ... </pre> </td></tr> </tbody></table></center> The list of reserved identifiers may be enlarged for next release. For the current release that list is made of: <code id='code1235' >eval</code>, <code id='code1236' >foreign</code> and <code id='code1237' >t</code>. </td></tr> </tbody></table><br/> Module <code id='code1241' ><em id='it1240' >clause</em></code>s can be:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1244" class="mark"></a><a name="main" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1248" align="left" colspan="1"><strong id='bold1246' >main</strong><em id='it1247' > name</em></td><td id="tc1249" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> This clause defines the entry point for a stand alone application to be procedure <code id='code1253' ><em id='it1252' >name</em></code> of arity one. Bigloo invokes this procedure at the beginning of execution providing the list, composed of the shell command line arguments, as its single argument.<br/><br/><center id='center1261' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1259' >(<font color="#1919af"><strong id='bold25988' >module</strong></font> <font color="#1919af"><strong id='bold25990' >foo</strong></font> (main start))<br/><br/>(<font color="#6959cf"><strong id='bold25992' >define</strong></font> (<font color="#6959cf"><strong id='bold25994' >start</strong></font> argv) (display argv) (newline)) </pre> </td></tr> </tbody></table></center> Then if this program is compiled into <code id='code1262' >foo</code> and invoked using the command <samp id='samp1263' >foo -t bar</samp>, the list which is the argument for the main procedure <code id='code1264' >start</code> would be <code id='code1265' >("foo" "-t" "bar")</code>. <br/><br/>The special form <code id='code1267' >args-parse</code> helps main function argument parsing (see <a href="bigloo-15.html#Command-Line-Parsing" class="inbound">Command Line Parsing</a>). </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1271" class="mark"></a><a name="include" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1275" align="left" colspan="1"><strong id='bold1273' >include</strong><em id='it1274' > file-name ...</em></td><td id="tc1276" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> <a name="g1279" class="mark"></a> This is a list of <code id='code1282' ><em id='it1281' >file-name</em></code>s to be included in the source file. Include files are not modules and may have a special syntax. Thus, besides containing Bigloo expressions, they can contain import and include clauses, which must be written in a single list whose first element is the keyword <code id='code1283' >directives</code>. Includes files can be used to include implementation-neutral Scheme expressions and definitions in a Bigloo module. Here is an example of an include file.<br/><br/><center id='center1288' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1286' ><font color="#ffa600"><em id='it25996' >;; </em></font>`foo.sch' (<font color="#6959cf"><strong id='bold25998' >define-struct</strong></font> <font color="#6959cf"><strong id='bold26000' >point</strong></font> x y) </pre> </td></tr> </tbody></table></center> and the module that includes the `foo.sch' file:<br/><br/><center id='center1296' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1294' ><font color="#ffa600"><em id='it26002' >;; </em></font>`foo.scm' (<font color="#1919af"><strong id='bold26004' >module</strong></font> <font color="#1919af"><strong id='bold26006' >foo</strong></font> (include <font color="red">"foo.sch"</font>))<br/><br/>(print (point 1 2)) </pre> </td></tr> </tbody></table></center> Include files, may contain module information. This is the role of the include <code id='code1297' >directives</code> clause here illustrated with the `bar.sch' example:<br/><br/><center id='center1306' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1304' ><font color="#ffa600"><em id='it26009' >;; </em></font>`bar.sch' <font color="#ffa600"><em id='it26011' >;; the directives</em></font> (directives (include <font color="red">"foobar.sch"</font>) (<font color="#1919af"><strong id='bold26014' >import</strong></font> <font color="#1919af"><strong id='bold26016' >hux</strong></font>))<br/><br/><font color="#ffa600"><em id='it26018' >;; expressions</em></font> (<font color="#6959cf"><strong id='bold26020' >define</strong></font> (<font color="#6959cf"><strong id='bold26022' >gee</strong></font> x) (print x)) </pre> </td></tr> </tbody></table></center> </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1310" class="mark"></a><a name="import" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1314" align="left" colspan="1"><strong id='bold1312' >import</strong><em id='it1313' > import ...</em></td><td id="tc1315" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> An <code id='code1319' ><em id='it1318' >import</em></code> is a list of the form:<br/><br/><center id='center1323' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ccccff"><pre class="prog" id='prog1321' ><import> ==> <iclause> ... <iclause> ==> (<bind-name> ... <bind-name> <module-name> <file-name> ...) | (<bind-name> ... <bind-name> <module-name>) | <module-name> | (<module-name> <file-name> ...) <bind-name> ==> <r5rs-ident> <module-name> ==> <r5rs-ident> <file-name> ==> <string> </pre> </td></tr> </tbody></table></center> The first alternative in <code id='code1325' ><em id='it1324' >iclause</em></code> imports the variable named <code id='code1327' ><em id='it1326' >bind-name</em></code> which is defined in the module <code id='code1329' ><em id='it1328' >module-name</em></code>, located in the files <code id='code1331' ><em id='it1330' >file-name</em></code> .... The second does the same but without specifying the name of the file where the module is located. The third and the fourth form import all the exported variables of the module <code id='code1333' ><em id='it1332' >module-name</em></code>.<br/><br/>Note: The need for specifying in which files modules are located comes from the fact that there is no automatic mapping between module names and files names. Such a mapping can be defined in a ``module access file'' (see <a href="bigloo-4.html#Module-Access-File" class="inbound">Module Access File</a>) or in the import clause itself, as in the first and fourth alternatives in <code id='code1336' ><em id='it1335' >iclause</em></code> above.<br/><br/>Here is an example of an import clause:<br/><br/><center id='center1356' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1354' >(<font color="#1919af"><strong id='bold26024' >module</strong></font> <font color="#1919af"><strong id='bold26026' >foo</strong></font> <font color="#1919af"><strong id='bold26028' > </strong></font>(<font color="#1919af"><strong id='bold26030' >import</strong></font><font color="#1919af"><strong id='bold26032' > </strong></font> <font color="#ffa600"><em id='it26034' >;; import all </em></font><code id='code1339' >bar</code> exported bindings: bar <font color="#ffa600"><em id='it26036' >;; import the </em></font><code id='code1340' >hux</code> binding exported by <font color="#ffa600"><em id='it26038' >;; the module </em></font><code id='code1341' >hux</code>: (hux hux) <font color="#ffa600"><em id='it26040' >;; import the </em></font><code id='code1342' >fun1</code>, <code id='code1343' >fun2</code> and <code id='code1344' >fun3</code> bindings exported by <font color="#ffa600"><em id='it26042' >;; the module </em></font><code id='code1345' >mod</code>: (fun1 fun2 fun3 mod) <font color="#ffa600"><em id='it26044' >;; import all </em></font><code id='code1346' >gee</code> bindings. the <code id='code1347' >gee</code> module <font color="#ffa600"><em id='it26046' >;; is located in a file called </em></font>`gee.scm': (gee <font color="red">"gee.scm"</font>))) </pre> </td></tr> </tbody></table></center> </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1360" class="mark"></a><a name="use" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1364" align="left" colspan="1"><strong id='bold1362' >use</strong><em id='it1363' > use ...</em></td><td id="tc1365" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> <code id='code1368' >use</code> has the same meaning as <code id='code1369' >import</code> except that modules which are <em id='emph1370' >used</em> are not initialized (see <a href="bigloo-4.html#Module-Initialization" class="inbound">Module Initialization</a>). Used modules are read before imported modules. </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1374" class="mark"></a><a name="with" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1378" align="left" colspan="1"><strong id='bold1376' >with</strong><em id='it1377' > with ...</em></td><td id="tc1379" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> This clause specifies a list of modules which have to be initialized at runtime and is used to force the initialization of modules which are never imported but which are required by an application (see <a href="bigloo-26.html#Embedded-Bigloo-applications" class="inbound">Embedded Bigloo applications</a>). </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1385" class="mark"></a><a name="export" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1389" align="left" colspan="1"><strong id='bold1387' >export</strong><em id='it1388' > export ...</em></td><td id="tc1390" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> In order to make a module's global bindings available to other modules, they have to be <em id='emph1393' >exported</em>. Export clauses are in charge of this task and an <code id='code1395' ><em id='it1394' >export</em></code> is a list of the form:<br/><br/><center id='center1399' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ccccff"><pre class="prog" id='prog1397' ><export> ==> <eclause> ... <eclause> ==> <ident> | (inline <ident> <ident> ...) | (generic <ident> <ident> <ident> ...) | (macro <ident> <ident> ...) | (syntax <ident> <ident> ...) | (<ident> <ident> ...) | <class> </pre> </td></tr> </tbody></table></center> The first form of <code id='code1401' ><em id='it1400' >eclause</em></code> allows the variable <code id='code1403' ><em id='it1402' >ident</em></code> be exported, the second allows the function <code id='code1405' ><em id='it1404' >ident</em></code>, always regarded as immutable when exported this way, to be exported and the third exports an inline-procedure (see <a href="bigloo-4.html#Inline-Procedures" class="inbound">Inline Procedures</a>) whose name is extracted from the first <code id='code1407' ><em id='it1406' >ident</em></code> after the word <code id='code1409' ><em id='it1408' >inline</em></code>. The last two are both connected with Bigloo's object system. The <code id='code1411' ><em id='it1410' >generic</em></code> clause exports generic functions (see <a href="bigloo-11.html#Generic-functions" class="inbound">Generic functions</a>) and <code id='code1413' ><em id='it1412' >class</em></code> clause exports classes (see <a href="bigloo-11.html#Class-declaration" class="inbound">Class declaration</a>).<br/><br/>Note: Only bindings defined in module <code id='code1415' >m</code> can be <em id='emph1416' >exported</em> by <code id='code1417' >m</code> (i.e. bindings <em id='emph1418' >imported</em> by <code id='code1419' >m</code> cannot be <em id='emph1420' >exported</em> by <code id='code1421' >m</code>).<br/><br/>Type information, specified in any <code id='code1424' ><em id='it1423' >ident</em></code> in an export clause, is used by Bigloo. Where no type information is given, a default generic type named <code id='code1425' >obj</code> is used.<br/><br/>Note: The last formal argument of a multiple arity function can not be typed because this argument is bound to be a <code id='code1427' >pair</code> or <code id='code1428' >null</code>. This union cannot be denoted by any type.<br/><br/>Here is an example of the module <code id='code1430' >foo</code> that exports bindings:<br/><br/><center id='center1443' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1441' >(<font color="#1919af"><strong id='bold26049' >module</strong></font> <font color="#1919af"><strong id='bold26051' >foo</strong></font> <font color="#1919af"><strong id='bold26053' > </strong></font>(<font color="#1919af"><strong id='bold26055' >export</strong></font><font color="#1919af"><strong id='bold26057' > </strong></font> <font color="#ffa600"><em id='it26059' >;; export the </em></font><code id='code1432' >bar</code> mutable variable bar <font color="#ffa600"><em id='it26061' >;; export the </em></font><code id='code1433' >hux</code> function. this <font color="#ffa600"><em id='it26063' >;; function takes exactly two arguments</em></font> (hux x y) <font color="#ffa600"><em id='it26065' >;; export the inline function </em></font><code id='code1434' >gee</code> <font color="#ffa600"><em id='it26067' >;; that takes at least one argument.</em></font> (<strong id='bold26069' >inline</strong> gee x . z))) </pre> </td></tr> </tbody></table></center> </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1447" class="mark"></a><a name="static" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1451" align="left" colspan="1"><strong id='bold1449' >static</strong><em id='it1450' > static ...</em></td><td id="tc1452" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> A <code id='code1455' >static</code> clause has exactly the same syntax as an export clause. However, bindings declared static are local to the module. Since the default scope of all bindings is static, <code id='code1456' >static</code> module clauses are useful only for program documentation.<br/><br/></td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1461" class="mark"></a><a name="from" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1465" align="left" colspan="1"><strong id='bold1463' >from</strong><em id='it1464' > from ...</em></td><td id="tc1466" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> <code id='code1469' >from</code> clauses have the syntax of <code id='code1470' >import</code> clauses. The allow the re-exportation of imported bindings. That is, any module can export any bindings imported via a <code id='code1472' ><em id='it1471' >from</em></code> clause.<br/><br/>As an example, suppose we have module <code id='code1474' >bar</code>:<br/><br/><center id='center1485' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1483' >(<font color="#1919af"><strong id='bold26070' >module</strong></font> <font color="#1919af"><strong id='bold26072' >bar</strong></font> (<font color="#1919af"><strong id='bold26074' >export</strong></font> (<font color="#1919af"><strong id='bold26076' >fun</strong></font>)))<br/><br/>(<font color="#6959cf"><strong id='bold26078' >define</strong></font> (<font color="#6959cf"><strong id='bold26080' >fun</strong></font>) <font color="red">"bar"</font>) </pre> </td></tr> </tbody></table></center> Now, suppose we have a module <code id='code1486' >foo</code> that imports <code id='code1487' >bar</code>, by the means of a <code id='code1488' >from</code> clause. Module <code id='code1489' >foo</code> is able to re-export the <code id='code1490' >bar</code> binding of module <code id='code1491' >bar</code>:<br/><br/><center id='center1498' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1496' >(<font color="#1919af"><strong id='bold26083' >module</strong></font> <font color="#1919af"><strong id='bold26085' >foo</strong></font> (from (fun bar <font color="red">"bar.scm"</font>))) </pre> </td></tr> </tbody></table></center> A third module, let's name it <code id='code1499' >gee</code>, importing module <code id='code1500' >foo</code>, can see the binding for function <code id='code1501' >bar</code>:<br/><br/><center id='center1511' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1509' >(<font color="#1919af"><strong id='bold26088' >module</strong></font> <font color="#1919af"><strong id='bold26090' >gee</strong></font> (<font color="#1919af"><strong id='bold26092' >import</strong></font> (<font color="#1919af"><strong id='bold26094' >foo</strong></font> <font color="red">"foo.scm"</font>)))<br/><br/>(print (fun)) </pre> </td></tr> </tbody></table></center> This feature is very useful when compiling modules exporting functions with type annotations. In particular, one may write:<br/><br/><center id='center1520' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1518' >(<font color="#1919af"><strong id='bold26097' >module</strong></font> <font color="#1919af"><strong id='bold26099' >foo</strong></font> (<font color="#1919af"><strong id='bold26101' >export</strong></font> (<strong id='bold26103' >class</strong> <font color="#1919af"><strong id='bold26104' >c1</strong></font> x))) </pre> </td></tr> </tbody></table></center> Then, <center id='center1534' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1532' >(<font color="#1919af"><strong id='bold26106' >module</strong></font> <font color="#1919af"><strong id='bold26108' >bar</strong></font> (<font color="#1919af"><strong id='bold26110' >import</strong></font> <font color="#1919af"><strong id='bold26112' >foo</strong></font>) (from foo) (<font color="#1919af"><strong id='bold26114' >export</strong></font> (<font color="#1919af"><strong id='bold26116' >fun</strong></font><font color="#00cf00"><strong id='bold26118' >::c1</strong></font>)))<br/><br/>(<font color="#6959cf"><strong id='bold26120' >define</strong></font> (<font color="#6959cf"><strong id='bold26122' >fun</strong></font>) (<strong id='bold26124' >instantiate</strong><font color="#00cf00"><strong id='bold26125' >::c1</strong></font> (x 10))) </pre> </td></tr> </tbody></table></center> And,<br/><br/><center id='center1545' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1543' >(<font color="#1919af"><strong id='bold26127' >module</strong></font> <font color="#1919af"><strong id='bold26129' >gee</strong></font> (<font color="#1919af"><strong id='bold26131' >import</strong></font> <font color="#1919af"><strong id='bold26133' >bar</strong></font>) (main main))<br/><br/>(<font color="#6959cf"><strong id='bold26135' >define</strong></font> (<font color="#6959cf"><strong id='bold26137' >main</strong></font> x) (<strong id='bold26139' >let</strong> ((o (fun))) (print o) (print (c1? o)))) </pre> </td></tr> </tbody></table></center> </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1549" class="mark"></a><a name="load" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1553" align="left" colspan="1"><strong id='bold1551' >load</strong><em id='it1552' > load ...</em></td><td id="tc1554" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> A <code id='code1558' ><em id='it1557' >load</em></code> is a list of the form:<br/><br/><center id='center1562' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ccccff"><pre class="prog" id='prog1560' ><load> ==> <lclause> ... <lclause> ==> (<module-name> <file-name>) | <module-name> </pre> </td></tr> </tbody></table></center> This clause forces Bigloo to load the module specified in the <code id='code1564' ><em id='it1563' >lclause</em></code> in the environment used by the macro expansion mechanism. This means that the user's macros can use all the bindings of all the <code id='code1565' >load</code>ed modules but the <code id='code1566' >load</code>ed bindings remains unknown to the compiler.<br/><br/>If the module <code id='code1568' >foo</code> is defined by:<br/><br/><center id='center1578' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1576' >(<font color="#1919af"><strong id='bold26140' >module</strong></font> <font color="#1919af"><strong id='bold26142' >foo</strong></font> (<font color="#1919af"><strong id='bold26144' >export</strong></font> (<font color="#1919af"><strong id='bold26146' >foo</strong></font> x)))<br/><br/>(<font color="#6959cf"><strong id='bold26148' >define</strong></font> (<font color="#6959cf"><strong id='bold26150' >foo</strong></font> x) `(cons ,x ,x)) </pre> </td></tr> </tbody></table></center> then,<br/><br/><center id='center1588' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1586' >(<font color="#1919af"><strong id='bold26152' >module</strong></font> <font color="#1919af"><strong id='bold26154' >gee</strong></font> (load (foo <font color="red">"foo.scm"</font>)))<br/><br/>(<font color="#6959cf"><strong id='bold26157' >define-macro</strong></font> (<font color="#6959cf"><strong id='bold26159' >gee</strong></font> x) `(cons ,(-fx x 1) ,(foo x)))<br/><br/>(gee 5) ==> (cons 4 (cons 5 5)) => (4 5 . 5) </pre> </td></tr> </tbody></table></center> </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1592" class="mark"></a><a name="eval" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1596" align="left" colspan="1"><strong id='bold1594' >eval</strong><em id='it1595' > eval...</em></td><td id="tc1597" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> This form allows interactions between compiled code and interpreted code. (See the Section <a href="bigloo-22.html#Eval" class="inbound">Eval command line options</a> for a presentation of compilation flags that enable compilation tuning for <code id='code1600' >eval</code>.) Each <code id='code1602' ><em id='it1601' >eval</em></code> has the following syntax:<br/><br/><center id='center1606' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ccccff"><pre class="prog" id='prog1604' ><eval> ==> (export-all) | (export-module) | (export-exports) | (export <bind-name>) | (export (@ <bind-name> <module-name>)) | (import <bind-name>) | (class <bind-name>) </pre> </td></tr> </tbody></table></center> <a name="g1607" class="mark"></a><a name="g1609" class="mark"></a><a name="g1611" class="mark"></a><a name="g1613" class="mark"></a> The first clause, <code id='code1615' >(export-all)</code>, exports all the variables bound in the module (i.e., the variables defined in the module and the imported variables). The second clause, <code id='code1616' >(export-module)</code>, exports all the module's variables (those declared static and exported) to the interpreter; the third exports all the exports (i.e. the ones present inside an <code id='code1617' >export</code> clause) variables to the interpreter; the fourth and fifth clause each export one variable to the interpreter. The last clause imports a variable from the interpreter and all such imported variables are immutable (i.e. they cannot be the first argument of a <code id='code1618' >set!</code> expression with the compiled code). Variables that are exported to the evaluators <em id='emph1619' >must</em> be exported. If a variable is exported to the evaluators but not exported within an <code id='code1620' >export</code> clause, the compiler will produce an error message.<br/><br/><center id='center1634' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1632' >(<font color="#1919af"><strong id='bold26161' >module</strong></font> <font color="#1919af"><strong id='bold26163' >foo</strong></font> (<font color="#1919af"><strong id='bold26165' >export</strong></font> (<font color="#1919af"><strong id='bold26167' >fib</strong></font> x)) (eval (<font color="#1919af"><strong id='bold26169' >export</strong></font> <font color="#1919af"><strong id='bold26171' >fib</strong></font>) (<font color="#1919af"><strong id='bold26173' >import</strong></font> <font color="#1919af"><strong id='bold26175' >bar</strong></font>)))<br/><br/>(<font color="#6959cf"><strong id='bold26177' >define</strong></font> (<font color="#6959cf"><strong id='bold26179' >fib</strong></font> x) ...) (print bar) </pre> </td></tr> </tbody></table></center> The clause <code id='code1635' >(class <bind-name>)</code> exports a class definition to the interpreter. This makes the class constructor, the class predicate and the slots access functions available from the interpreter. The form <code id='code1638' >(instantiate::<code id='code1637' ><em id='it1636' >class</em></code> ...)</code> and <code id='code1641' >(with-access::<code id='code1640' ><em id='it1639' >class</em></code> ...)</code> are also available from the interpreter. </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1645" class="mark"></a><a name="extern" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1649" align="left" colspan="1"><strong id='bold1647' >extern</strong><em id='it1648' > extern ...</em></td><td id="tc1650" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> Extern (aka foreign) clauses will be explained in the foreign interface (see <a href="bigloo-26.html#C-Interface" class="inbound">C Interface</a>). </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1656" class="mark"></a><a name="java" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1660" align="left" colspan="1"><strong id='bold1658' >java</strong><em id='it1659' > java ...</em></td><td id="tc1661" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> Java clauses will be explained in the Java interface (see <a href="bigloo-27.html#Java-Interface" class="inbound">Java Interface</a>). </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1667" class="mark"></a><a name="option" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1671" align="left" colspan="1"><strong id='bold1669' >option</strong><em id='it1670' > option ...</em></td><td id="tc1672" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> This clause enables variables which affect compilation to be set from inside a module and since the expressions, <code id='code1676' ><em id='it1675' >option</em></code> ..., are evaluated <em id='emph1677' >when compiling</em>, no code is compiled for them. They are allowed to make side effects and to change the values of the global variables which describe how the compiler must compile. Usually they allow the control variables, which are described when Bigloo is invoked with the <code id='code1678' >-help2</code> option, to be set as in the following example:<br/><br/><center id='center1687' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1685' >(<font color="#1919af"><strong id='bold26181' >module</strong></font> <font color="#1919af"><strong id='bold26183' >examplar</strong></font> (option (<strong id='bold26185' >set!</strong> *debug* 3) (<strong id='bold26186' >set!</strong> *verbose* 2)))<br/><br/>(print 'dummy) </pre> </td></tr> </tbody></table></center> Whatever arguments are passed on the command line, Bigloo will compile this module in both verbose mode and debug mode. </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1691" class="mark"></a><a name="library" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1695" align="left" colspan="1"><strong id='bold1693' >library</strong><em id='it1694' > library ...</em></td><td id="tc1696" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> This clause enables libraries (see <a href="bigloo-28.html#Bigloo-Libraries" class="inbound">Bigloo Libraries</a>) when compiling and linking Bigloo modules. The expressions <code id='code1700' ><em id='it1699' >library</em></code> ... are symbols naming the libraries to be used.<br/><br/>Here is an example of a module declaration which makes use of a library named <code id='code1702' >format</code>:<br/><br/><center id='center1713' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1711' >(<font color="#1919af"><strong id='bold26187' >module</strong></font> <font color="#1919af"><strong id='bold26189' >test</strong></font> (<font color="#1919af"><strong id='bold26191' >library</strong></font> <font color="#1919af"><strong id='bold26193' >format</strong></font>) (main test-format) (<font color="#1919af"><strong id='bold26195' >import</strong></font> (<font color="#1919af"><strong id='bold26197' >test2</strong></font> <font color="red">"test2.scm"</font>))) </pre> </td></tr> </tbody></table></center> </td></tr> </tbody></table><br/> <table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1717" class="mark"></a><a name="type" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1721" align="left" colspan="1"><strong id='bold1719' >type</strong><em id='it1720' > type ...</em></td><td id="tc1722" align="right" colspan="1">bigloo module clause</td></tr> </tbody></table> This forms is used to define builtin Bigloo types. It is not recommended to use it in user programs. So, it is left undocumented. </td></tr> </tbody></table><br/><br/><br/></div><br> <!-- Module initialization --> <a name="Module-initialization"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">3.3 Module initialization</font> </h3></td></tr></table> </div><div class="section"> <a name="Module-Initialization" class="mark"></a> <em id='emph1728' >Initializing</em> a module means evaluating, at runtime, its top level forms (global bindings are top level forms).<br/><br/>When a module, <code id='code1731' ><em id='it1730' >module1</em></code>, imports a module, <code id='code1733' ><em id='it1732' >module2</em></code>, <code id='code1735' ><em id='it1734' >module2</em></code> is initialized before <code id='code1737' ><em id='it1736' >module1</em></code>. Modules are initialized only once, nothing being done if a module already met during initialization is met again. Library modules are initialized before user modules and imported modules are initialized in the same order as they appear in import clauses.<br/><br/>Here is a first example with two modules. First the module <code id='code1739' >foo</code>:<br/><br/><center id='center1752' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1750' ><font color="#ffa600"><em id='it26200' >;; module foo</em></font> (<font color="#1919af"><strong id='bold26202' >module</strong></font> <font color="#1919af"><strong id='bold26204' >foo</strong></font> (main main) (<font color="#1919af"><strong id='bold26206' >import</strong></font> (<font color="#1919af"><strong id='bold26208' >bar</strong></font> <font color="red">"bar.scm"</font>)))<br/><br/>(<font color="#6959cf"><strong id='bold26211' >define</strong></font> (<font color="#6959cf"><strong id='bold26213' >main</strong></font> argv) (print <font color="red">"argv: "</font> argv)) (print <font color="red">"foo"</font>) </pre> </td></tr> </tbody></table></center> Then the module <code id='code1753' >bar</code> <center id='center1760' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1758' ><font color="#ffa600"><em id='it26217' >;; module bar</em></font> (<font color="#1919af"><strong id='bold26219' >module</strong></font> <font color="#1919af"><strong id='bold26221' >bar</strong></font>)<br/><br/>(print <font color="red">"bar"</font>) </pre> </td></tr> </tbody></table></center> These can be compiled into the executable <code id='code1762' ><em id='it1761' >a.out</em></code> with: <center id='center1765' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1763' >$ bigloo -c foo.scm $ bigloo -c bar.scm $ bigloo foo.o bar.o </pre> </td></tr> </tbody></table></center> Execution of <code id='code1767' ><em id='it1766' >a.out</em></code> produces: <center id='center1770' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1768' >$ a.out -| bar foo argv: (a.out) </pre> </td></tr> </tbody></table></center> The explanation is: <ul class="itemize" id='itemize1785' ><li>module <code id='code1771' >foo</code> contains the program entry point so this is where initialization begins. </li> <li>because <code id='code1773' >foo</code> imports module <code id='code1774' >bar</code>, <code id='code1775' >bar</code> must be initialized <em id='emph1776' >before</em> <code id='code1777' >foo</code>. This explains why the word <code id='code1778' >bar</code> is printed before anything else. </li> <li>module initialization for <code id='code1780' >foo</code> is completed before <code id='code1781' >main</code> is called. This explains why word <code id='code1782' >foo</code> is printed before <code id='code1783' >main</code> is entered. </li> </ul> Let's consider another example with 3 modules: <center id='center1799' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1797' ><font color="#ffa600"><em id='it26224' >;; </em></font><code id='code1786' >module1</code> (<font color="#1919af"><strong id='bold26226' >module</strong></font> <font color="#1919af"><strong id='bold26228' >module1</strong></font> (main main) (<font color="#1919af"><strong id='bold26230' >import</strong></font> (<font color="#1919af"><strong id='bold26232' >module2</strong></font> <font color="red">"module2.scm"</font>)))<br/><br/>(<font color="#6959cf"><strong id='bold26235' >define</strong></font> (<font color="#6959cf"><strong id='bold26237' >main</strong></font> argv) (print <font color="red">"argv: "</font> argv))<br/><br/>(print <font color="red">"module1"</font>) </pre> </td></tr> </tbody></table></center> The second module: <center id='center1810' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1808' ><font color="#ffa600"><em id='it26241' >;; </em></font><code id='code1800' >module2</code> (<font color="#1919af"><strong id='bold26243' >module</strong></font> <font color="#1919af"><strong id='bold26245' >module2</strong></font> (<font color="#1919af"><strong id='bold26247' >import</strong></font> (<font color="#1919af"><strong id='bold26249' >module3</strong></font> <font color="red">"module3.scm"</font>)))<br/><br/>(print <font color="red">"module2"</font>) </pre> </td></tr> </tbody></table></center> The third module: <center id='center1820' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1818' ><font color="#ffa600"><em id='it26253' >;; </em></font><code id='code1811' >module3</code> (<font color="#1919af"><strong id='bold26255' >module</strong></font> <font color="#1919af"><strong id='bold26257' >module3</strong></font> (<font color="#1919af"><strong id='bold26259' >import</strong></font> (<font color="#1919af"><strong id='bold26261' >module1</strong></font> <font color="red">"module1.scm"</font>))) (print <font color="red">"module3"</font>) </pre> </td></tr> </tbody></table></center> Compile with: <center id='center1823' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1821' >$ bigloo module1.scm -c $ bigloo module2.scm -c $ bigloo module3.scm -c $ bigloo module1.o module2.o module3.o </pre> </td></tr> </tbody></table></center> Execution produces:<br/><br/><center id='center1827' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1825' >$ a.out -| module3 module2 module1 argv: (a.out) </pre> </td></tr> </tbody></table></center> The order of module initialization can be explicitly specified using <code id='code1828' >with</code> and <code id='code1829' >use</code> clauses. </div><br> <!-- Qualified notation --> <a name="Qualified-notation"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">3.4 Qualified notation</font> </h3></td></tr></table> </div><div class="section"> <a name="Qualified-Notation" class="mark"></a><a name="g1830" class="mark"></a><a name="g1832" class="mark"></a> Global variables can be referenced using implicit notation or using <em id='emph1834' >qualified</em> notation. Implicit notation is used when variables are referenced just by their name whereas qualified notation is used when variables are referenced by their name and the name of the module which defines them. Qualified notation has the following syntax:<br/><br/><center id='center1838' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ccccff"><pre class="prog" id='prog1836' >(@ <bind-name> <module-name>) </pre> </td></tr> </tbody></table></center> and is useful when several imported modules export a variable with the same name. Using qualified notations instead of short notation only affects compilation.<br/><br/>When several variables are defined under the same identifier, the compiler uses the two following rules in order to decide which variable is selected by an implicit reference: 1) the variable defined in a module has a higher precedence than all imported variables, 2) imported variables have a higher precedence than library variables.<br/><br/></div><br> <!-- Inline procedures --> <a name="Inline-procedures"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">3.5 Inline procedures</font> </h3></td></tr></table> </div><div class="section"> <a name="Inline-Procedures" class="mark"></a><a name="g1841" class="mark"></a> Bigloo allows procedures called <em id='emph1843' >inline</em> and which differ from normal ones only in the type of code planted. An inline procedure is a first class object which can be manipulated in the same way as any other procedure but when Bigloo sees a reference to one, rather than generating a C function call to the function, the body of the inline procedure is open-coded. The definition of an inline is given in the following way:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g1846" class="mark"></a><a name="define-inline" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1850" align="left" colspan="1"><strong id='bold1848' >define-inline</strong><em id='it1849' > (name args ...) body</em></td><td id="tc1851" align="right" colspan="1">bigloo syntax</td></tr> </tbody></table> <table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc1856" align="left" colspan="1"><strong id='bold1854' >define-inline</strong><em id='it1855' > (name args ... . arg) body</em></td><td id="tc1857" align="right" colspan="1">bigloo syntax</td></tr> </tbody></table> Apart from the initial word, this form has the same syntax as that used by <code id='code1860' >define</code> for procedures. Inline procedures are exportable which means that the compiler scans imported files to find the bodies of all inline procedures. Here is a small example of a module which exports an inline and a module which imports it.<br/><br/><center id='center1871' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1869' ><font color="#ffa600"><em id='it26265' >;; the exporter module</em></font> (<font color="#1919af"><strong id='bold26267' >module</strong></font> <font color="#1919af"><strong id='bold26269' >exporter</strong></font> (<font color="#1919af"><strong id='bold26271' >export</strong></font> (<strong id='bold26273' >inline</strong> <font color="#1919af"><strong id='bold26274' >make-list</strong></font> . objs)))<br/><br/>(<font color="#6959cf"><strong id='bold26276' >define-inline</strong></font> (<font color="#6959cf"><strong id='bold26278' >make-list</strong></font> . objs) objs) </pre> </td></tr> </tbody></table></center> <center id='center1879' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1877' ><font color="#ffa600"><em id='it26280' >;; the importer module</em></font> (<font color="#1919af"><strong id='bold26282' >module</strong></font> <font color="#1919af"><strong id='bold26284' >importer</strong></font> (<font color="#1919af"><strong id='bold26286' >import</strong></font> <font color="#1919af"><strong id='bold26288' >exporter</strong></font>))<br/><br/>(print (make-list 1 2 3 4 5)) </pre> </td></tr> </tbody></table></center> Because of the open-coding of the exporter procedure, the above print statement is equivalent to:<br/><br/><center id='center1884' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog1882' >(print (<strong id='bold26290' >let</strong> ((objs (list 1 2 3 4 5))) objs)) </pre> </td></tr> </tbody></table></center> Any procedure can be an inline. Also any exported procedure can be an inline provided all global variables and functions it uses are also exported.<br/><br/>Note: Bigloo can decide to inline procedures declared with <code id='code1886' >define</code> but this can be achieved only with local procedures whereas procedures declared with the <code id='code1887' >define-inline</code> form are open-coded even through module importation.<br/><br/>Note: Procedures declared <em id='emph1889' >inline</em> are macro expanded with the macro defined in the module where they are invoked. That is, if module <code id='code1890' >module1</code> declares an inline procedure <code id='code1891' >p</code> and module <code id='code1892' >module2</code> imports it, <code id='code1893' >p</code> may have two different macro-expansions: one for <code id='code1894' >module1</code> and one for <code id='code1895' >module2</code>. </td></tr> </tbody></table><br/> </div><br> <!-- Module access file --> <a name="Module-access-file"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">3.6 Module access file</font> </h3></td></tr></table> </div><div class="section"> <a name="Module-Access-File" class="mark"></a><a name="g1898" class="mark"></a><a name="g1900" class="mark"></a><a name="g1902" class="mark"></a><a name="g1904" class="mark"></a> Bigloo is different from languages such as C where a module is defined by a file. For Bigloo, the module name is not necessarily the name of the file where the text of the module is written and modules can even be split across several files.<br/><br/>Since modules are defined independently of files, it is necessary to make a link between a module and its files and there are two ways of doing this. Choosing an import clause where the file-names are specified or creating a ``module access file''. Such a file must contain only one <code id='code1908' ><em id='it1907' >list</em></code>, each element of the list being of the form:<br/><br/>(module-name "file-name" ... "file-name")<br/><br/>Use the <samp id='samp1911' >-afile <file></samp> option to specify the ``module accessfile'' when compiling. By default Bigloo checks if a file named <code id='code1912' >.afile</code> exists. If it exists it is loaded as a module access file.<br/><br/>See <a href="bigloo-31.html#Compiler-Description" class="inbound">The Bigloo command line</a>.<br/><br/>Note: The Bigloo distribution contains a tool, <code id='code1915' >bglafile</code>, that can automatically build a ``module access file''. See the manpage for <code id='code1916' >bglafile</code> for details.<br/><br/></div><br> <!-- Reading path --> <a name="Reading-path"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">3.7 Reading path</font> </h3></td></tr></table> </div><div class="section"> <a name="Reading-Path" class="mark"></a><a name="g1918" class="mark"></a> Imported, included or loaded files are sought first in the current directory and then in the directories, sequentially from start to end, of the list in the <code id='code1920' >*load-path*</code> <a name="g1921" class="mark"></a>variable. This variable, initially set to the empty list, can be reset by the <samp id='samp1923' >-I</samp> option of the compiler. </div><br> </div></td> </tr></table><div class="skribe-ending"> <hr> <p class="ending" id='paragraph26296' ><font size="-1"> This <span class="sc">Html</span> page has been produced by <a href="http://www.inria.fr/mimosa/fp/Skribe" class="http">Skribe</a>. <br/> Last update <em id='it26294' >Tue Jun 2 11:43:26 2009</em>.</font></p></div> </body> </html>