Sophie

Sophie

distrib > Fedora > 13 > i386 > media > os > by-pkgid > 52a37fb77746ef557a2ec666070d732e > files > 36

bigloo-doc-3.2b-3.fc12.i686.rpm

<!-- 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>29. Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009 -- SRFIs</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='center30979'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30969" align="center" colspan="1"><font color="#ffffff"><strong id='bold30967'
>main page</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30976" align="center" colspan="1"><table width="100%" border="0" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc30972" align="left" valign="top" colspan="1"><strong id='bold30971'
>top:</strong></td><td id="tc30973" 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='center30989'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30983" align="center" colspan="1"><font color="#ffffff"><strong id='bold30981'
>SRFIs</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30986" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc">
<tbody>
 <tr><td valign="top" align="left">29.1</td><td colspan="4" width="100%"><a href="bigloo-30.html#SRFI-0">SRFI 0</a></td></tr>
 <tr><td valign="top" align="left">29.2</td><td colspan="4" width="100%"><a href="bigloo-30.html#SRFI-1">SRFI 1</a></td></tr>
 <tr><td valign="top" align="left">29.3</td><td colspan="4" width="100%"><a href="bigloo-30.html#SRFI-22">SRFI 22</a></td></tr>
 <tr><td></td><td valign="top" align="left">29.3.1</td><td colspan="3" width="100%"><a href="bigloo-30.html#An-example-of-SRFI-22-script">An example of SRFI-22 script</a></td></tr>
 <tr><td></td><td valign="top" align="left">29.3.2</td><td colspan="3" width="100%"><a href="bigloo-30.html#Lazy-compilation-with-SRFI-22">Lazy compilation with SRFI-22</a></td></tr>
</tbody>
</table>
</td></tr>
</tbody></table>
</center>
<br/><br/><center id='center30999'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc30993" align="center" colspan="1"><font color="#ffffff"><strong id='bold30991'
>Chapters</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc30996" 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="SRFIs" class="mark"></a><a name="g24951" class="mark"></a>
Bigloo supports various SRFIs (Scheme Request For Implementation). Some of
them are integrated in the Bigloo core libraries. Some others are implemented
by the means of Bigloo libraries (see <a href="bigloo-28.html#Bigloo-Libraries" class="inbound">Bigloo Libraries</a>). Only the
first ones are described in the manual. 
Check the Bigloo web page
(<a href="http://www.inria.fr/mimosa/fp/Bigloo">http://www.inria.fr/mimosa/fp/Bigloo</a>).

The current Bigloo core library support the following SRFIs:<br/><br/><ul class="itemize" id='itemize24975'
><li><code id='code24954'
>srfi-0</code> (Conditional execution).
</li>
<li><code id='code24956'
>srfi-2</code> (AND-LET*: an AND with local bindings, a guarded LET* special form).
</li>
<li><code id='code24958'
>srfi-6</code> (Basic String Ports).
</li>
<li><code id='code24960'
>srfi-8</code> (Binding to multiple values).
</li>
<li><code id='code24962'
>srfi-9</code> (<em id='emph24963'
>Records</em> specification).
</li>
<li><code id='code24965'
>srfi-18</code> (Multithreading support). 
</li>
<li><code id='code24967'
>srfi-22</code> (Script interpreter invocation). 
</li>
<li><code id='code24969'
>srfi-28</code> (Basic Format Strings). 
</li>
<li><code id='code24971'
>srfi-30</code> (Multi-line comments).
</li>
<li><code id='code24973'
>srfi-34</code> (Exception Handling for Programs).
</li>
</ul>
<!-- SRFI 0 -->
<a name="SRFI-0"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">29.1 SRFI 0</font>
</h3></td></tr></table>
</div><div class="section">
<a name="g24976" class="mark"></a><a name="g24978" class="mark"></a>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g24981" class="mark"></a><a name="cond-expand" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc24985" align="left" colspan="1"><strong id='bold24983'
>cond-expand</strong><em id='it24984'
> [clause]</em></td><td id="tc24986" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>

The <code id='code24989'
>cond-expand</code> form tests for the existence of features at
macro-expansion time. It either expands into the body of one of its
clauses or signals and error during syntactic
processing. <code id='code24990'
>cond-expand</code> expands into the body of the first clause
whose feature requirement is currently satisfied (the <code id='code24991'
>else</code>
clause, if present, is selected if none of the previous clauses is
selected).<br/><br/>A feature requirement has an obvious interpretation as a logical
formula, where the variables have meaning <em id='emph24993'
>true</em> is the feature
corresponding to the feature identifier, as specified in the <em id='emph24994'
>SRFI</em>
registry, is in effect at the location of the <code id='code24995'
>cond-expand</code> form,
and <em id='emph24996'
>false</em> otherwise. A feature requirement is satisfied it its
formula is true under this interpretation. The formula may make use of
identifier, <code id='code24997'
>and</code>, <code id='code24998'
>or</code> and <code id='code24999'
>not</code> operators.<br/><br/>Since Bigloo version 3.1b, <code id='code25001'
>cond-expand</code> formula may use the new
<code id='code25002'
>library</code> operator that checks if a library exists and is available.
Its syntax is: <code id='code25003'
>(library &lt;libname&gt;)</code>.<br/><br/>Examples: <br/><br/><center id='center25015'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog25013'
>(write (cond-expand
          (srfi-0 (* 1 2))
          ((or (<font color="#1919af"><strong id='bold31000'
>library</strong></font> <font color="#1919af"><strong id='bold31002'
>fthread</strong></font>) (<font color="#1919af"><strong id='bold31004'
>library</strong></font> <font color="#1919af"><strong id='bold31006'
>pthread</strong></font>)) (- 4 1))
          (else (+ 3 4))))
   -| 2<br/><br/>(cond-expand 
   (bigloo (<font color="#6959cf"><strong id='bold31008'
>define</strong></font> (<font color="#6959cf"><strong id='bold31010'
>command-line-arguments</strong></font>) (command-line)))
   (else (<font color="#6959cf"><strong id='bold31012'
>define</strong></font> (<font color="#6959cf"><strong id='bold31014'
>command-line-arguments</strong></font>) '())))
</pre>
</td></tr>
</tbody></table></center>

The second example assumes that <code id='code25016'
>bigloo</code> is an alias for the SRFI 
associated with the specification of Bigloo (i.e. the documentation for that
Scheme system). <br/><br/>When writing portable code, the case used for the feature identifier
should match the one in the SRFI registry. This is to ensure that the
feature identifier will be correctly recognized whether or not the
Scheme system is case-sensitive. To support case-insensitive Scheme
systems, the feature identifiers in the SRFI registry are guaranteed to
be unique even when ignoring the case.<br/><br/>In order to distinguish Bigloo versions, the following symbols are
recognized in <code id='code25019'
>cond-expand</code> forms.<br/><br/><ul class="itemize" id='itemize25029'
><li><code id='code25021'
>bigloo</code>
</li>
<li><code id='code25023'
>bigloo&lt;branch-release&gt;</code>
</li>
<li><code id='code25025'
>bigloo&lt;major-release&gt;</code>
</li>
<li><code id='code25027'
>bigloo&lt;major-release&gt;&lt;minor-release&gt;</code>
</li>
</ul>
When finalizers have been configured, the two following symbols are
recognized by <code id='code25030'
>cond-expand</code>:<br/><br/><ul class="itemize" id='itemize25036'
><li><code id='code25032'
>bigloo-finalizer</code>
</li>
<li><code id='code25034'
>bigloo-weakptr</code>
</li>
</ul>
Bigloo implements differents SRFI for the compiler and the interpreter.
Thus, their are two Bigloo SRFI registers. One for the compiler and one
for the interpreter. Bigloo compiler SRFI register contains at least the 
following symbols: <br/><br/><ul class="itemize" id='itemize25056'
><li><code id='code25038'
>srfi-0</code>
</li>
<li><code id='code25040'
>srfi-1</code>
</li>
<li><code id='code25042'
>srfi-2</code>
</li>
<li><code id='code25044'
>srfi-6</code>
</li>
<li><code id='code25046'
>srfi-8</code>
</li>
<li><code id='code25048'
>srfi-9</code>
</li>
<li><code id='code25050'
>srfi-22</code>
</li>
<li><code id='code25052'
>srfi-28</code>
</li>
<li><code id='code25054'
>srfi-30</code>
</li>
</ul>
With respect to the currently used Bigloo back-end, one of these symbols
is registered:<br/><br/><ul class="itemize" id='itemize25062'
><li><code id='code25058'
>bigloo-c</code>
</li>
<li><code id='code25060'
>bigloo-jvm</code>
</li>
</ul>
Bigloo compiler implements the following SRFI:<br/><br/><ul class="itemize" id='itemize25072'
><li><code id='code25064'
>bigloo</code>
</li>
<li><code id='code25066'
>bigloo-compile</code> 
</li>
<li><code id='code25068'
>bigloo&lt;major-release&gt;</code>
</li>
<li><code id='code25070'
>bigloo&lt;major-release&gt;&lt;minor-release&gt;</code>
</li>
</ul>
Then the <code id='code25073'
>-g</code> flag is used, the Bigloo compiler additionally implements
the SRFI:<br/><br/><ul class="itemize" id='itemize25077'
><li><code id='code25075'
>bigloo-debug</code>
</li>
</ul><br/><br/>Bigloo interpreter implements the following SRFI: <br/><br/><ul class="itemize" id='itemize25088'
><li><code id='code25080'
>bigloo</code>
</li>
<li><code id='code25082'
>bigloo-eval</code> 
</li>
<li><code id='code25084'
>bigloo&lt;major-release&gt;</code>
</li>
<li><code id='code25086'
>bigloo&lt;major-release&gt;&lt;minor-release&gt;</code>
</li>
</ul>
When a library is used, the name of the library is added to the compiler SRFI
register. That is:<br/><br/><center id='center25097'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog25095'
>(<font color="#1919af"><strong id='bold31016'
>module</strong></font> <font color="#1919af"><strong id='bold31018'
>foo</strong></font>
   (<font color="#1919af"><strong id='bold31020'
>library</strong></font> <font color="#1919af"><strong id='bold31022'
>srfi1</strong></font>))<br/><br/>(print (cond-expand (srfi1 'with-srfi1) (else 'nothing)))
   -| 'with-srfi1
(print (eval '(cond-expand (srfi1 'with-srfi1) (else 'nothing))))
   -| 'with-srfi1
</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="g25101" class="mark"></a><a name="register-eval-srfi!" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc25105" align="left" colspan="1"><strong id='bold25103'
>register-eval-srfi!</strong><em id='it25104'
> srfi-name</em></td><td id="tc25106" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
This argument <code id='code25110'
><em id='it25109'
>srfi-name</em></code> is a symbol. It registers <code id='code25112'
><em id='it25111'
>srfi-name</em></code>
in the Bigloo interpreter SRFI register. This function must only be
used when implementing a library. The code of that library must contain
one unique call to <code id='code25113'
>register-eval-srfi!</code>. Let's suppose, for instance,
a <code id='code25114'
>format</code> library. The implementation for that library must contain
an expression like:<br/><br/><center id='center25118'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog25116'
>(register-eval-srfi! 'format)
</pre>
</td></tr>
</tbody></table></center>

Calling <code id='code25119'
>(register-eval-srfi! name)</code> makes <code id='code25120'
>name</code> supported
by interpreted <code id='code25121'
>cond-expand</code> forms. <br/><br/><em id='emph25123'
>Note:</em> There is no <code id='code25124'
>register-compiler-srfi!</code> because the
compiler automatically registers SRFI when the <code id='code25125'
>-library</code>
flags are used. However, it exists several ways to tell the
compiler that it actually supports some srfis when compiling some modules.<br/><br/><ul class="itemize" id='itemize25142'
><li>The first way is to insert calls to <code id='code25127'
>register-eval-srfi!</code> in the
<code id='code25128'
>.bigloorc</code> file (see <a href="bigloo-31.html#Compiler-Description" class="inbound">Compiler Description</a>). <br/><br/></li>
<li>The second, is to use <code id='code25131'
>option</code> (see <a href="bigloo-4.html#Module-Declaration" class="inbound">Module Declaration</a>) module 
clause, such as:<br/><br/><center id='center25138'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog25136'
>(<font color="#1919af"><strong id='bold31024'
>module</strong></font> <font color="#1919af"><strong id='bold31026'
>example</strong></font>
   ...
   (option (register-srfi! 'srfi-foobar)))<br/><br/>...
</pre>
</td></tr>
</tbody></table></center>

</li>
<li>The last way is to use the command line option <code id='code25140'
>-srfi</code>
(see <a href="bigloo-31.html#Compiler-Description" class="inbound">Compiler Description</a>).
</li>
</ul>
</td></tr>
</tbody></table><br/>
</div><br>
<!-- SRFI 1 -->
<a name="SRFI-1"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">29.2 SRFI 1</font>
</h3></td></tr></table>
</div><div class="section">
<a name="g25145" class="mark"></a>
The SRFI 1 is implemented as a Bigloo library. Hence, in order to use
the functions it provides, a module must import it.<br/><br/><center id='center25155'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog25153'
>(<font color="#1919af"><strong id='bold31028'
>module</strong></font> <font color="#1919af"><strong id='bold31030'
>ex</strong></font>
   (<font color="#1919af"><strong id='bold31032'
>library</strong></font> <font color="#1919af"><strong id='bold31034'
>srfi1</strong></font>))<br/><br/>(print (find-tail even? '(3 1 37 -8 -5 0 0)))
 =&gt; '(-8 -5 0 0))
</pre>
</td></tr>
</tbody></table></center>

</div><br>
<!-- SRFI 22 -->
<a name="SRFI-22"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">29.3 SRFI 22</font>
</h3></td></tr></table>
</div><div class="section">
<a name="g25156" class="mark"></a><a name="g25158" class="mark"></a>
The SRFI 22 describes basic prerequisites for running Scheme programs as
Unix scripts in a uniform way. A file (henceforth a <em id='emph25160'
>scipt</em>) conforming
SRFI 22 has the following syntax:<br/><br/><center id='center25165'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog25163'
>&lt;script&gt;         ==&gt; &lt;script prelude&gt;? &lt;program&gt;
&lt;script prelude&gt; ==&gt; <code id='code25162'
>#!</code> &lt;space&gt; &lt;all but linebreak&gt;* &lt;linebreak&gt;
</pre>
</td></tr>
</tbody></table></center>

A Scheme script interpreter loads the <code id='code25166'
>&lt;script&gt;</code>. It ignores the
script prelude and interprets the rest of the file according to the
language dialect specified by the name of the interpreter.<br/><br/>The Scheme script interpreter may also load a different file after
making a reasonable check that loading it is semantically equivalent to
loading <code id='code25168'
>&lt;script&gt;</code>. For example, the script interpreter may assume
that a file with a related name (say, with an additional extension) is a
compiled version of <code id='code25169'
>&lt;script&gt;</code>.<br/><br/><!-- An example of SRFI-22 script -->
<a name="An-example-of-SRFI-22-script"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">29.3.1 An example of SRFI-22 script</font>
</h3></td></tr></table>
</div><div class="subsection">

Let us consider the following Bigloo script located in a file
`foo.scm':<br/><br/><center id='center25179'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog25177'
>#! /usr/bin/env ./execute
(<font color="#1919af"><strong id='bold31036'
>module</strong></font> <font color="#1919af"><strong id='bold31038'
>foo</strong></font>
   (main main))<br/><br/>(<font color="#6959cf"><strong id='bold31040'
>define</strong></font> (<font color="#6959cf"><strong id='bold31042'
>main</strong></font> argv)
   (print <font color="red">&quot;foo: &quot;</font> argv))
</pre>
</td></tr>
</tbody></table></center>

Let us consider the following `execute' shell script:<br/><br/><center id='center25183'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog25181'
>$ cat &gt; execute
#!/bin/sh
bigloo -i $*
</pre>
</td></tr>
</tbody></table></center>

Provided that `foo.scm' as the execute flag switched on, it is
possible to <em id='emph25184'
>execute</em> it:<br/><br/><center id='center25188'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog25186'
>$ chmod u+x foo.scm
$ ./foo.scm
  -| foo: (./foo.scm)
</pre>
</td></tr>
</tbody></table></center>

The same Bigloo module can be compiled and executed such as:<br/><br/><center id='center25192'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog25190'
>$ bigloo foo.scm
$ ./a.out
  -| foo: (a.out)
</pre>
</td></tr>
</tbody></table></center>

</div>
<!-- Lazy compilation with SRFI-22 -->
<a name="Lazy-compilation-with-SRFI-22"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">29.3.2 Lazy compilation with SRFI-22</font>
</h3></td></tr></table>
</div><div class="subsection">

SRFI-22 can be used to implement <em id='emph25193'
>lazy</em> compilation. For instance,
let us consider the following shell script:<br/><br/><center id='center25197'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog25195'
>$ cat &gt; bgl
#!/bin/sh
SOURCEFILE=$1
case $SOURCEFILE in
    *.scm)
        OUTFILE=${SOURCEFILE%.scm}
        if ( bigloo -s -o $OUTFILE $SOURCEFILE ); then
            /bin/rm $OUTFILE.o
            shift
            ./$OUTFILE $&#x40;
        fi
        ;;
    *)
        echo Error: need a \*.scm file!
        ;;
esac
</pre>
</td></tr>
</tbody></table></center>

And the following Bigloo script:<br/><br/><center id='center25206'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog25204'
>#! /usr/bin/env ./bgl
(<font color="#1919af"><strong id='bold31045'
>module</strong></font> <font color="#1919af"><strong id='bold31047'
>foo</strong></font>
   (main main))<br/><br/>(<font color="#6959cf"><strong id='bold31049'
>define</strong></font> (<font color="#6959cf"><strong id='bold31051'
>main</strong></font> argv)
   (print <font color="red">&quot;foo: &quot;</font> argv))
</pre>
</td></tr>
</tbody></table></center>

When executed in the following way:<br/><br/><center id='center25210'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccffcc"><pre class="prog" id='prog25208'
>$ chmod u+x foo.scm
$ ./foo.scm
  -| foo: (./foo.scm)
</pre>
</td></tr>
</tbody></table></center>

The Bigloo module <code id='code25211'
>foo.scm</code> will first be compiled and then executed.
Of course, one may consider more complex compiler drivers where it is
first checked that the module is not already compiled.<br/><br/><br/>

</div>
</div><br>
</div></td>
</tr></table><div class="skribe-ending">
<hr> 
<p class="ending" id='paragraph31059'
><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='it31057'
>Tue Jun  2 11:43:27 2009</em>.</font></p></div>
</body>
</html>