<!-- 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>9. Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009 -- Structures and Records</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='center27458' ><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody> <tr bgcolor="#8381de"><th id="tc27448" align="center" colspan="1"><font color="#ffffff"><strong id='bold27446' >main page</strong></font></th></tr> <tr bgcolor="#ffffff"><td id="tc27455" align="center" colspan="1"><table width="100%" border="0" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc27451" align="left" valign="top" colspan="1"><strong id='bold27450' >top:</strong></td><td id="tc27452" 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='center27468' ><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody> <tr bgcolor="#8381de"><th id="tc27462" align="center" colspan="1"><font color="#ffffff"><strong id='bold27460' >Structures and Records</strong></font></th></tr> <tr bgcolor="#ffffff"><td id="tc27465" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc"> <tbody> <tr><td valign="top" align="left">9.1</td><td colspan="4" width="100%"><a href="bigloo-10.html#Structures">Structures</a></td></tr> <tr><td valign="top" align="left">9.2</td><td colspan="4" width="100%"><a href="bigloo-10.html#Records-(SRFI-9)">Records (SRFI-9)</a></td></tr> </tbody> </table> </td></tr> </tbody></table> </center> <br/><br/><center id='center27478' ><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody> <tr bgcolor="#8381de"><th id="tc27472" align="center" colspan="1"><font color="#ffffff"><strong id='bold27470' >Chapters</strong></font></th></tr> <tr bgcolor="#ffffff"><td id="tc27475" 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="Structures-and-Records" class="mark"></a> Bigloo supports two kinds of enumerated types: the <em id='emph14275' >structures</em> and the <em id='emph14276' >records</em>. They offer similar facilities. Structures were pre-existing to records and they are maintained mainly for backward compatiblity. Recors are compliant with the Scheme request for implementation 9.<br/><br/> <!-- Structures --> <a name="Structures"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">9.1 Structures</font> </h3></td></tr></table> </div><div class="section"> <a name="Structures" class="mark"></a><a name="g14278" class="mark"></a>There is, in Bigloo, a new class of objects: structures, which are equivalent to C <code id='code14280' >struct</code>.<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g14283" class="mark"></a><a name="define-struct" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc14287" align="left" colspan="1"><strong id='bold14285' >define-struct</strong><em id='it14286' > name field...</em></td><td id="tc14288" align="right" colspan="1">bigloo syntax</td></tr> </tbody></table> This form defines a structure with name <code id='code14292' ><em id='it14291' >name</em></code>, which is a symbol, having fields <code id='code14294' ><em id='it14293' >field</em></code>... which are symbols or lists, each list being composed of a symbol and a default value. This form creates several functions: creator, predicate, accessor and assigner functions. The name of each function is built in the following way: <ul class="itemize" id='itemize14315' ><li>Creator: <code id='code14297' >make-<code id='code14296' ><em id='it14295' >name</em></code></code> </li> <li>Predicate: <code id='code14301' ><code id='code14300' ><em id='it14299' >name</em></code>?</code> </li> <li>Accessor: <code id='code14307' ><code id='code14304' ><em id='it14303' >name</em></code>-<code id='code14306' ><em id='it14305' >field</em></code></code> </li> <li>Assigner: <code id='code14313' ><code id='code14310' ><em id='it14309' >name</em></code>-<code id='code14312' ><em id='it14311' >field</em></code>-set!</code> </li> </ul> Function <code id='code14318' >make-<code id='code14317' ><em id='it14316' >name</em></code></code> accepts an optional argument. If provided, all the slots of the created structures are filled with it. The creator named <code id='code14319' >name</code> accepts as many arguments as the number of slots of the structure. This function allocates a structure and fills each of its slots with its corresponding argument.<br/><br/>If a structure is created using <code id='code14323' >make-<code id='code14322' ><em id='it14321' >name</em></code></code> and no initialization value is provided, the slot default values (when provided) are used to initialize the new structure. For instance, the execution of the program:<br/><br/><center id='center14330' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14328' >(<font color="#6959cf"><strong id='bold27479' >define-struct</strong></font> <font color="#6959cf"><strong id='bold27481' >pt1</strong></font> a b) (<font color="#6959cf"><strong id='bold27483' >define-struct</strong></font> <font color="#6959cf"><strong id='bold27485' >pt2</strong></font> (h 4) (g 6))<br/><br/>(make-pt1) => #{PT1 () ()} (make-pt1 5) => #{PT1 5 5} (make-pt2) => #{PT2 4 6} (make-pt2 5) => #{PT2 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="g14334" class="mark"></a><a name="struct?" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc14338" align="left" colspan="1"><strong id='bold14336' >struct?</strong><em id='it14337' > obj</em></td><td id="tc14339" align="right" colspan="1">bigloo procedure</td></tr> </tbody></table> Returns <code id='code14342' >#t</code> if and only if <code id='code14344' ><em id='it14343' >obj</em></code> is a structure. </td></tr> </tbody></table><br/> </div><br> <!-- Records (SRFI-9) --> <a name="Records-(SRFI-9)"></a> <div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">9.2 Records (SRFI-9)</font> </h3></td></tr></table> </div><div class="section"> <a name="Records-(SRFI-9)" class="mark"></a><a name="g14347" class="mark"></a><a name="g14349" class="mark"></a> Bigloo supports records has specified by SRFI-9. This section is a copy of the SRFI-9 specification by Richard Kelsey. This SRFI describes syntax for creating new data types, called record types. A predicate, constructor, and field accessors and modifiers are defined for each record type. Each new record type is distinct from all existing types, including other record types and Scheme's predefined types.<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody> <tr><td><a name="g14353" class="mark"></a><a name="define-record-type" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody> <tr><td id="tc14357" align="left" colspan="1"><strong id='bold14355' >define-record-type</strong><em id='it14356' > expression...</em></td><td id="tc14358" align="right" colspan="1">syntax</td></tr> </tbody></table> The syntax of a record-type definition is: <br/><br/><center id='center14365' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ccccff"><pre class="prog" id='prog14363' ><record-type-definition> ==> (<code id='code14362' >define-record-type</code> <type-name> (<constructor-name> <field-tag> ...) <predicate-name> <field-spec> ...) <field-spec> ==> (<field-tag> <accessor-name>) | (<field-tag> <accessor-name> <modifier-name>) <field-tag> ==> <identifier> <accessor-name> ==> <identifier> <predicate-name> ==> <identifier> <modifier-name> ==> <identifier> <type-name> ==> <identifier> </pre> </td></tr> </tbody></table></center> <code id='code14366' >Define-record-type</code> is generative: each use creates a new record type that is distinct from all existing types, including other record types and Scheme's predefined types. Record-type definitions may only occur at top-level (there are two possible semantics for `internal' record-type definitions, generative and nongenerative, and no consensus as to which is better).<br/><br/>an instance of <code id='code14368' >define-record-type</code> is equivalent to the following definitions:<br/><br/><br/><ul class="itemize" id='itemize14393' ><li><code id='code14370' ><type-name></code> is bound to a representation of the record type itself. Operations on record types, such as defining print methods, reflection, etc. are left to other SRFIs.<br/><br/></li> <li><code id='code14373' ><constructor-name></code> is bound to a procedure that takes as many arguments as the re are <code id='code14374' ><field-tag></code>s in the <code id='code14375' >(<constructor-name> ...)</code> subform and returns a new <code id='code14376' ><type-name></code> record. Fields whose tags are listed with <code id='code14377' ><constructor-name></code> have the corresponding argument as their initial value. The initial values of all other fields are unspecified. <br/><br/></li> <li><code id='code14380' ><predicate-name></code> is a predicate that returns <code id='code14381' >#t</code> when given a value returned by <code id='code14382' ><constructor-name></code> and <code id='code14383' >#f</code> for everything else.<br/><br/></li> <li>Each <code id='code14386' ><accessor-name></code> is a procedure that takes a record of type <code id='code14387' ><type-name></code> and returns the current value of the corresponding field. It is an error to pass an accessor a value which is not a record of the appropriate type. <br/><br/></li> <li>Each <code id='code14390' ><modifier-name></code> is a procedure that takes a record of type <code id='code14391' ><type-name></code> and a value which becomes the new value of the corresponding field; an unspecified value is returned. It is an error to pass a modifier a first argument which is not a record of the appropriate type. </li> </ul> Records are disjoint from the types listed in Section 4.2 of R5RS. <br/><br/>Seting the value of any of these identifiers has no effect on the behavior of any of their original values.<br/><br/>The following <br/><br/><center id='center14399' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14397' >(define-record-type pare (kons x y) pare? (x kar set-kar!) (y kdr)) </pre> </td></tr> </tbody></table></center> defines <code id='code14400' >kons</code> to be a constructor, <code id='code14401' >kar</code> and <code id='code14402' >kdr</code> to be accessors, <code id='code14403' >set-kar!</code> to be a modifier, and <code id='code14404' >pare?</code> to be a predicate for <code id='code14405' >pare</code>s. <br/><br/><center id='center14410' ><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody> <tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14408' > (pare? (kons 1 2)) => #t (pare? (cons 1 2)) => #f (kar (kons 1 2)) => 1 (kdr (kons 1 2)) => 2 (<strong id='bold27487' >let</strong> ((k (kons 1 2))) (set-kar! k 3) (kar k)) => 3 </pre> </td></tr> </tbody></table></center> </td></tr> </tbody></table><br/> </div><br> </div></td> </tr></table><div class="skribe-ending"> <hr> <p class="ending" id='paragraph27493' ><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='it27491' >Tue Jun 2 11:43:27 2009</em>.</font></p></div> </body> </html>