Sophie

Sophie

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

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>10. Bigloo<br/>A ``practical Scheme compiler''<br/>User manual for version 3.2b<br/>June 2009 -- Object System</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='center27507'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc27497" align="center" colspan="1"><font color="#ffffff"><strong id='bold27495'
>main page</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc27504" align="center" colspan="1"><table width="100%" border="0" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc27500" align="left" valign="top" colspan="1"><strong id='bold27499'
>top:</strong></td><td id="tc27501" 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='center27517'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc27511" align="center" colspan="1"><font color="#ffffff"><strong id='bold27509'
>Object System</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc27514" align="center" colspan="1"><table cellspacing="1" cellpadding="1" width="100%" class="toc">
<tbody>
 <tr><td valign="top" align="left">10.1</td><td colspan="4" width="100%"><a href="bigloo-11.html#Class-declaration">Class declaration</a></td></tr>
 <tr><td valign="top" align="left">10.2</td><td colspan="4" width="100%"><a href="bigloo-11.html#Creating-and-accessing-objects">Creating and accessing objects</a></td></tr>
 <tr><td valign="top" align="left">10.3</td><td colspan="4" width="100%"><a href="bigloo-11.html#Generic-functions">Generic functions</a></td></tr>
 <tr><td valign="top" align="left">10.4</td><td colspan="4" width="100%"><a href="bigloo-11.html#Widening-and-shrinking">Widening and shrinking</a></td></tr>
 <tr><td valign="top" align="left">10.5</td><td colspan="4" width="100%"><a href="bigloo-11.html#Object-library">Object library</a></td></tr>
 <tr><td></td><td valign="top" align="left">10.5.1</td><td colspan="3" width="100%"><a href="bigloo-11.html#Classes-handling">Classes handling</a></td></tr>
 <tr><td></td><td valign="top" align="left">10.5.2</td><td colspan="3" width="100%"><a href="bigloo-11.html#Object-handling">Object handling</a></td></tr>
 <tr><td valign="top" align="left">10.6</td><td colspan="4" width="100%"><a href="bigloo-11.html#Object-serialization">Object serialization</a></td></tr>
 <tr><td valign="top" align="left">10.7</td><td colspan="4" width="100%"><a href="bigloo-11.html#Equality">Equality</a></td></tr>
 <tr><td valign="top" align="left">10.8</td><td colspan="4" width="100%"><a href="bigloo-11.html#Introspection">Introspection</a></td></tr>
</tbody>
</table>
</td></tr>
</tbody></table>
</center>
<br/><br/><center id='center27527'
><table width="97%" border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" frame="box" rules="none"><tbody>
<tr bgcolor="#8381de"><th id="tc27521" align="center" colspan="1"><font color="#ffffff"><strong id='bold27519'
>Chapters</strong></font></th></tr>
<tr bgcolor="#ffffff"><td id="tc27524" 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="Object-System" class="mark"></a><a name="g14413" class="mark"></a><a name="g14415" class="mark"></a>
Bigloo's object system is designed to be as simple as possible and
belongs to the <span class="sc">Clos</span> [Bobrow et al. 88] object system family
in that it uses <em id='emph14418'
>classes</em>, <em id='emph14419'
>generic functions</em> and
<em id='emph14420'
>methods</em>. Its design has been strongly influenced by C. Queinnec's
<span class="sc">Meroon</span> [Queinnec93] It does not include any meta object protocol.<br/><br/><br/>
<!-- Class declaration -->
<a name="Class-declaration"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">10.1 Class declaration</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Class-declaration" class="mark"></a><a name="g14423" class="mark"></a>
Classes are defined in a module declaration. A class declaration can
take place in a compiled or interpreted module. If a class declaration
takes place in a static module clause (see Section <a href="bigloo-4.html#Module-Declaration" class="inbound">Module Declaration</a>) its scope is limited to the current module but if it
takes place in an export module clause, its scope is extended to all
modules that import the current module. The syntax of a class
declaration is:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g14427" class="mark"></a><a name="class" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc14431" align="left" colspan="1"><strong id='bold14429'
>class</strong><em id='it14430'
> ident field ...</em></td><td id="tc14432" align="right" colspan="1">bigloo module clause</td></tr>
</tbody></table>

<center id='center14462'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ccccff"><pre class="prog" id='prog14460'
>&lt;class&gt; ==&gt; <code id='code14435'
>(class</code> &lt;ident&gt; &lt;constructor&gt;? &lt;field&gt;+<code id='code14436'
>)</code>
     | <code id='code14437'
>(final-class</code> &lt;ident&gt; &lt;constructor&gt;? &lt;field&gt;+<code id='code14438'
>)</code>
     | <code id='code14439'
>(wide-class</code> &lt;ident&gt; &lt;constructor&gt;? &lt;field&gt;+<code id='code14440'
>)</code>
     | <code id='code14441'
>(abstract-class</code> &lt;ident&gt; &lt;constructor&gt;? &lt;field&gt;+<code id='code14442'
>)</code>
&lt;constructor&gt; ==&gt; <code id='code14443'
>(</code> &lt;expr&gt; <code id='code14444'
>)</code>
&lt;field&gt; ==&gt; &lt;ident&gt;
     | <code id='code14445'
>(*</code> &lt;ident&gt;<code id='code14446'
>)</code>
     | <code id='code14447'
>(</code>&lt;ident&gt; &lt;field-prop&gt;<code id='code14448'
>)</code>
     | <code id='code14449'
>(*</code> &lt;ident&gt; &lt;field-prop&gt;<code id='code14450'
>)</code>
&lt;field-prop&gt; ==&gt; <code id='code14451'
>read-only</code>
     | <code id='code14452'
>(get</code> &lt;bigloo-exp&gt;<code id='code14453'
>)</code>
     | <code id='code14454'
>(set</code> &lt;bigloo-exp&gt;<code id='code14455'
>)</code>
     | <code id='code14456'
>(default</code> &lt;bigloo-exp&gt;<code id='code14457'
>)</code>
     | <code id='code14458'
>(info</code> &lt;bigloo-exp&gt;<code id='code14459'
>)</code>
</pre>
</td></tr>
</tbody></table></center>
<a name="g14463" class="mark"></a><a name="g14465" class="mark"></a><a name="g14467" class="mark"></a><a name="g14469" class="mark"></a>
A class is a Bigloo type and the class identifier is extracted from the
&lt;ident&gt; of the class definition. If &lt;ident&gt; is also a
&lt;typed-ident&gt;, the type part of this identifier denote the super-class
of the class. If &lt;ident&gt; is a &lt;<span class="sc">Ieee</span>-ident&gt;, the super-class of
the class is the root of the inheritance tree, the <code id='code14472'
>object</code> class. This
<code id='code14473'
>object</code> class is the only pre-existing class.<br/><br/><em id='emph14475'
>Final classes</em> can only be sub-classed by <em id='emph14476'
>wide classes</em>.
<em id='emph14477'
>Wide classes</em> (only for compiled modules) can only inherit from <em id='emph14478'
>final classes</em>. 
<em id='emph14479'
>abstract classes</em> can't be instantiated. <br/><br/>Wide-classes cannot be defined within the interpreter.<br/><br/>The optional constructor is an expression that must evaluate to a one
argument function. This function is automatically invoked each time
a new class instance is created. The constructor is passed the fresh
instance. If a class has not defined a constructor the super class'
constructors are searched. The first constructor found is invoked. 
A constructor may be a generic function with a method specified
for one or more classes.<br/><br/>A class field may be a <em id='emph14483'
>typed class field</em> which is achieved
by using a &lt;typed-ident&gt; instead of a &lt;<span class="sc">Ieee</span>-ident&gt;
for the &lt;ident&gt; value. <br/><br/>A class field defined as <code id='code14486'
>(* ...)</code> is an indexed field and holds a
sequence of items. The length of this sequence is defined at allocation
time.<br/><br/>Field marked with <code id='code14488'
>read-only</code> declaration are immutables.<br/><br/><code id='code14490'
>Default</code> declarations allow default field values. For
indexed fields, the default value is the default value of each
element of the sequence.<br/><br/>For the means of an example, the traditional points and colored points 
can be defined as:
<center id='center14504'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14502'
>(<font color="#1919af"><strong id='bold27528'
>module</strong></font> <font color="#1919af"><strong id='bold27530'
>example</strong></font>
   (<strong id='bold27532'
>static</strong> (abstract-class pt)
           (<strong id='bold27533'
>class</strong> point<font color="#00cf00"><strong id='bold27534'
>::pt</strong></font>
              x<font color="#00cf00"><strong id='bold27536'
>::double</strong></font> 
              y<font color="#00cf00"><strong id='bold27538'
>::double</strong></font>)
           (<strong id='bold27540'
>class</strong> point-C<font color="#00cf00"><strong id='bold27541'
>::point</strong></font> 
              (color<font color="#00cf00"><strong id='bold27543'
>::string</strong></font> read-only))))
</pre>
</td></tr>
</tbody></table></center>

We illustrate indexed fields, final and wide classes by the example:
<center id='center14517'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14515'
>(<font color="#1919af"><strong id='bold27545'
>module</strong></font> <font color="#1919af"><strong id='bold27547'
>example</strong></font>
   (<font color="#1919af"><strong id='bold27549'
>export</strong></font> (<font color="#1919af"><strong id='bold27551'
>final-class</strong></font> person 
               (name<font color="#00cf00"><strong id='bold27553'
>::string</strong></font> (default <font color="red">&quot;Jones&quot;</font>))
               (sex read-only)
               (* children<font color="#00cf00"><strong id='bold27556'
>::person</strong></font>))
           (<strong id='bold27558'
>wide-class</strong> married-person<font color="#00cf00"><strong id='bold27559'
>::person</strong></font>
               mate<font color="#00cf00"><strong id='bold27561'
>::person</strong></font>)))
</pre>
</td></tr>
</tbody></table></center>

Fields may be virtual. A field is virtual as soon as its declaration
contain a <code id='code14518'
>get</code> attribute. Virtual fields have no 
physical implementation within the instance. When defining a virtual
field, the class declaration implements a <em id='emph14519'
>getter</em> and a <em id='emph14520'
>setter</em>
if that field is not a read only field. Access to the virtual field will
rely on invocation of the user <em id='emph14521'
>getter</em> and user <em id='emph14522'
>setter</em>. For
instance:<br/><br/><center id='center14548'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14546'
>(<font color="#1919af"><strong id='bold27563'
>module</strong></font> <font color="#1919af"><strong id='bold27565'
>example</strong></font>
   (<strong id='bold27567'
>static</strong> (<strong id='bold27568'
>class</strong> complex
              mag<font color="#00cf00"><strong id='bold27569'
>::double</strong></font>
              angle<font color="#00cf00"><strong id='bold27571'
>::double</strong></font>              
              (real<font color="#00cf00"><strong id='bold27573'
>::double</strong></font> (get (<strong id='bold27575'
>lambda</strong> (p)
                                    (<strong id='bold27576'
>with-access</strong><font color="#00cf00"><strong id='bold27577'
>::complex</strong></font> p (mag angle)
                                       (* mag (cos angle)))))
                            read-only)
              (imag<font color="#00cf00"><strong id='bold27579'
>::double</strong></font> (get (<strong id='bold27581'
>lambda</strong> (p)
                                    (<strong id='bold27582'
>with-access</strong><font color="#00cf00"><strong id='bold27583'
>::complex</strong></font> p (mag angle)
                                       (* mag (sin angle)))))
                            read-only))))<br/><br/>(<strong id='bold27585'
>let</strong> ((p (<strong id='bold27586'
>instantiate</strong><font color="#00cf00"><strong id='bold27587'
>::complex</strong></font> (mag 1.0) (angle 2.18))))
   (<strong id='bold27589'
>with-access</strong><font color="#00cf00"><strong id='bold27590'
>::complex</strong></font> p (real imag)
      (print <font color="red">&quot;real: &quot;</font> real)
      (print <font color="red">&quot;imag: &quot;</font> imag)))
</pre>
</td></tr>
</tbody></table></center>

Virtual fields cannot be associated default values. Virtual fields may
not be indexed fields. If a virtual field is not provided with a 
setter it must be annotated as read only.<br/><br/><code id='code14550'
>Info</code> declarations allow arbitrary user information field values.
This value can be retrieved by introspection, by the means of the
<code id='code14551'
>class-field-info</code> introspection function.<br/><br/>For the means of an example, with add to information to the slot of
the point class.
<center id='center14561'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14559'
>(<font color="#1919af"><strong id='bold27594'
>module</strong></font> <font color="#1919af"><strong id='bold27596'
>example</strong></font>
   (<strong id='bold27598'
>static</strong> (<strong id='bold27599'
>class</strong> point 
              (x<font color="#00cf00"><strong id='bold27600'
>::double</strong></font> (info '(range 0.0 10.0)))
              (y<font color="#00cf00"><strong id='bold27602'
>::double</strong></font> (info '(range -1.0 1.0)))))
</pre>
</td></tr>
</tbody></table></center>

</td></tr>
</tbody></table><br/>
</div><br>
<!-- Creating and accessing objects -->
<a name="Creating-and-accessing-objects"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">10.2 Creating and accessing objects</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Creating-and-accessing-objects" class="mark"></a><a name="g14564" class="mark"></a>
Bigloo automatically creates functions to allocate and manipulate objects.
Let us suppose the class declaration:
<center id='center14579'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14577'
>(<strong id='bold27604'
>class</strong> <code id='code14567'
><em id='it14566'
>class</em></code>
   <code id='code14569'
><em id='it14568'
>field1</em></code>::<code id='code14571'
><em id='it14570'
>type1</em></code>
   (* <code id='code14573'
><em id='it14572'
>field2</em></code>::<code id='code14575'
><em id='it14574'
>type2</em></code>))
</pre>
</td></tr>
</tbody></table></center>

Theses functions are:
<ul class="itemize" id='itemize14719'
><li>A nil instance:
<center id='center14586'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14584'
>(<code id='code14581'
><em id='it14580'
>class</em></code>-nil::<code id='code14583'
><em id='it14582'
>class</em></code>)
</pre>
</td></tr>
</tbody></table></center>

This function returns the NIL pre-existing class instance. This instance plays 
the role of <code id='code14587'
>void *</code> in C or <code id='code14588'
>null</code> in Java. The value of each field
is unspecified but correct with respect to the Bigloo type system. Each 
call to <code id='code14591'
><code id='code14590'
><em id='it14589'
>class</em></code>-nil</code> returns the same object (in the sense of 
<code id='code14592'
>eq?</code>).<br/><br/></li>
<li>A creator:
<center id='center14606'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14604'
>(make-<code id='code14596'
><em id='it14595'
>class</em></code>::<code id='code14598'
><em id='it14597'
>class</em></code> ::<code id='code14600'
><em id='it14599'
>type1</em></code> <font color="#00cf00"><strong id='bold27605'
>::long</strong></font> ::<code id='code14602'
><em id='it14601'
>type2</em></code>)
</pre>
</td></tr>
</tbody></table></center>

This function allocates a fresh instance of <code id='code14608'
><em id='it14607'
>class</em></code> and fills the field
values with the argument. The length of the indexed field <code id='code14610'
><em id='it14609'
>field2</em></code> is
given as argument of the function.<br/><br/>Example:
<center id='center14617'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14615'
>(<strong id='bold27607'
>class</strong> truc 
   x<font color="#00cf00"><strong id='bold27608'
>::char</strong></font> 
   (* y<font color="#00cf00"><strong id='bold27610'
>::bstring</strong></font>))
</pre>
</td></tr>
</tbody></table></center>

The prototype of the allocation function is:
<center id='center14624'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14622'
>(make-truc<font color="#00cf00"><strong id='bold27612'
>::truc</strong></font> x<font color="#00cf00"><strong id='bold27614'
>::char</strong></font> 
                 y-len<font color="#00cf00"><strong id='bold27616'
>::long</strong></font> 
                 y<font color="#00cf00"><strong id='bold27618'
>::bstring</strong></font>)
</pre>
</td></tr>
</tbody></table></center>

The indexed values of the <code id='code14625'
>y</code> and <code id='code14626'
>z</code> fields will be set
to the values of the formal parameters <code id='code14627'
>y</code> and <code id='code14628'
>z</code> respectively. <br/><br/></li>
<li>A filler:
<center id='center14642'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14640'
>(fill-<code id='code14632'
><em id='it14631'
>class</em></code>! ::<code id='code14634'
><em id='it14633'
>class</em></code> ::<code id='code14636'
><em id='it14635'
>type1</em></code> <font color="#00cf00"><strong id='bold27620'
>::long</strong></font> ::<code id='code14638'
><em id='it14637'
>type2</em></code>)
</pre>
</td></tr>
</tbody></table></center>

This function accepts the same arguments as the creator augmented with
one allocated instance. This instance is filled up with the provided values.
For indexed fields, the same initial value is used to fill up the array
of values.<br/><br/></li>
<li>A type checker:
<center id='center14653'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14651'
>(<code id='code14646'
><em id='it14645'
>class</em></code>?<font color="#00cf00"><strong id='bold27622'
>::bool</strong></font> <code id='code14648'
><em id='it14647'
>obj</em></code><font color="#00cf00"><strong id='bold27624'
>::obj</strong></font>)
</pre>
</td></tr>
</tbody></table></center>

This function returns <code id='code14654'
>#t</code> if <code id='code14656'
><em id='it14655'
>obj</em></code> is an instance
of <code id='code14658'
><em id='it14657'
>class</em></code> or an instance of a sub-class of <code id='code14660'
><em id='it14659'
>class</em></code>, otherwise,
it returns <code id='code14661'
>#f</code>.<br/><br/></li>
<li>Accessors and mutators:
<center id='center14709'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14707'
>(<code id='code14665'
><em id='it14664'
>class</em></code>-<code id='code14667'
><em id='it14666'
>field_1</em></code>::<code id='code14669'
><em id='it14668'
>type_1</em></code> ::<code id='code14671'
><em id='it14670'
>class</em></code>)
(<code id='code14673'
><em id='it14672'
>class</em></code>-<code id='code14675'
><em id='it14674'
>field_1</em></code>-set!<font color="#00cf00"><strong id='bold27626'
>::obj</strong></font> ::<code id='code14677'
><em id='it14676'
>class</em></code> ::<code id='code14679'
><em id='it14678'
>type_1</em></code>)
(<code id='code14681'
><em id='it14680'
>class</em></code>-<code id='code14683'
><em id='it14682'
>field_2</em></code>-len<font color="#00cf00"><strong id='bold27628'
>::long</strong></font> ::<code id='code14685'
><em id='it14684'
>class</em></code>)
(<code id='code14687'
><em id='it14686'
>class</em></code>-<code id='code14689'
><em id='it14688'
>field_2</em></code>-ref::<code id='code14691'
><em id='it14690'
>type_2</em></code> ::<code id='code14693'
><em id='it14692'
>class</em></code> <font color="#00cf00"><strong id='bold27630'
>::long</strong></font>)
(<code id='code14695'
><em id='it14694'
>class</em></code>-<code id='code14697'
><em id='it14696'
>field_2</em></code>-set!<font color="#00cf00"><strong id='bold27632'
>::obj</strong></font> ::<code id='code14699'
><em id='it14698'
>class</em></code> <font color="#00cf00"><strong id='bold27634'
>::long</strong></font> ::<code id='code14701'
><em id='it14700'
>type_2</em></code>)
</pre>
</td></tr>
</tbody></table></center>

Declaring a field <code id='code14710'
>read-only</code> prevents Bigloo from
generating an associated <code id='code14715'
><code id='code14712'
><em id='it14711'
>class</em></code>-<code id='code14714'
><em id='it14713'
>field_i</em></code>-set!</code>
function. The length of the indexed field is <code id='code14716'
>
read-only</code>. Thus they do not have mutator functions.<br/><br/></li>
</ul>
Some syntax helps with allocation and access to objects.
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g14721" class="mark"></a><a name="with-access::" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc14727" align="left" colspan="1"><strong id='bold14723'
>with-access::</strong><em id='it14726'
><code id='code14725'
><em id='it14724'
>class</em></code> obj (binding...) body</em></td><td id="tc14728" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<a name="g14731" class="mark"></a>
A reference to any of the variables defined in as a <code id='code14734'
><em id='it14733'
>binding</em></code> is
replaced by the appropriate field access form. This is true for both
reference and assignment. A <code id='code14736'
><em id='it14735'
>binding</em></code> is either a symbol or a list
of two symbols. In the first place, it denotes a field. In the second
case, it denotes an aliases field.<br/><br/>For instance:
<center id='center14747'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14745'
>(<strong id='bold27636'
>with-access</strong><font color="#00cf00"><strong id='bold27637'
>::point</strong></font> p (x (y1 y))
   (<strong id='bold27639'
>with-access</strong><font color="#00cf00"><strong id='bold27640'
>::point</strong></font> p2 (y)
      (<strong id='bold27642'
>set!</strong> x (- x))
      (<strong id='bold27643'
>set!</strong> y1 (- y1 y))))
is equivalent to:
(<strong id='bold27644'
>begin</strong>
   (point-x-set! p (- (point-x p)))
   (point-y-set! p (- (point-y p) (point-y p2))))
</pre>
</td></tr>
</tbody></table></center>

When an indexed field is referenced inside the binding part of a
<code id='code14748'
>with-access</code> form, the functions that accesses and changes the
fields are bound inside the body of the <code id='code14749'
>with-access</code>. In addition,
a variable reporting the length of the field is also bound. For a field
<code id='code14751'
><em id='it14750'
>fd</em></code>, the getter function is <code id='code14756'
>(<code id='code14753'
><em id='it14752'
>fd</em></code>-ref <code id='code14755'
><em id='it14754'
>offset</em></code>)</code>, the
setter is <code id='code14763'
>(<code id='code14758'
><em id='it14757'
>fd</em></code>-set! <code id='code14760'
><em id='it14759'
>offset</em></code> <code id='code14762'
><em id='it14761'
>value</em></code>)</code>, the length
variable is <code id='code14766'
><code id='code14765'
><em id='it14764'
>fd</em></code>-len</code>.
For instance:
<center id='center14780'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14778'
>(<strong id='bold27645'
>with-access</strong><font color="#00cf00"><strong id='bold27646'
>::truc</strong></font> o (y)
   (print <font color="red">&quot;length: &quot;</font> y-len)
   (print <font color="red">&quot;old y-ref(0): &quot;</font> (y-ref 0))
   (y-set! 0 <font color="red">&quot;foo&quot;</font>)
   (print <font color="red">&quot;new y-ref(0): &quot;</font> (y-ref 0)))
is equivalent to:
(<strong id='bold27652'
>begin</strong>
   (print <font color="red">&quot;length: &quot;</font> (truc-y-len o))
   (print <font color="red">&quot;old y-ref(0): &quot;</font> (truc-y-ref o 0))
   (truc-y-set! o 0 <font color="red">&quot;foo&quot;</font>)
   (print <font color="red">&quot;new y-ref(0): &quot;</font> (truc-y-ref o 0)))
</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="g14784" class="mark"></a><a name="instantiate::" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc14790" align="left" colspan="1"><strong id='bold14786'
>instantiate::</strong><em id='it14789'
><code id='code14788'
><em id='it14787'
>class</em></code> (ident value)...</em></td><td id="tc14791" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<a name="g14794" class="mark"></a>This forms allocates object of class <code id='code14797'
><em id='it14796'
>class</em></code> and fills the fields with
values found in the list of parameters (note that field are explicitly
named and that there is no ordering for field naming). Field values which
are not provided in the parameter list must have been declared with a
<code id='code14798'
>default</code> value which is used to initialize the corresponding
field.<br/><br/>For instance:
<center id='center14802'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14800'
>(make-point 0 0)
</pre>
</td></tr>
</tbody></table></center>
is equivalent to:
<center id='center14807'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14805'
>(<strong id='bold27657'
>instantiate</strong><font color="#00cf00"><strong id='bold27658'
>::point</strong></font> (x 0) (y 0))
</pre>
</td></tr>
</tbody></table></center>

Indexed field must be provided with exactly two values. The first is the 
length of the indexed field and the second is the default value of each 
element of the indexed field.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g14811" class="mark"></a><a name="co-instantiate" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc14819" align="left" colspan="1"><strong id='bold14813'
>co-instantiate</strong><em id='it14818'
> ((<code id='code14815'
><em id='it14814'
>var</em></code> <code id='code14817'
><em id='it14816'
>value</em></code>) ...) body</em></td><td id="tc14820" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>

This form is only available from compiled modules. In other words, it
is not available from the interpreter. It permits the creation of
recursive instances. It is specially useful for creating instances for
which class declarations contain cyclic type references (for instance
a class <code id='code14823'
>c1</code> for a which a field is declared of class <code id='code14824'
>c2</code>
and a class <code id='code14825'
>c2</code> for which a class is declared of type
<code id='code14826'
>c1</code>). The syntax of a <code id='code14827'
>co-instantiate</code> form is similar to a
<code id='code14828'
>let</code> form. However the only legal <code id='code14830'
><em id='it14829'
>values</em></code> are
<code id='code14831'
>instantiate</code> forms. The variables introduced in the binding of a
<code id='code14832'
>co-instantiate</code> form are bound in <code id='code14834'
><em id='it14833'
>body</em></code>. In addition, they
are <em id='emph14835'
>partially</em> bound in the <code id='code14837'
><em id='it14836'
>values</em></code> expressions. In a
<code id='code14839'
><em id='it14838'
>value</em></code> position, a variable <code id='code14841'
><em id='it14840'
>var</em></code> can only be used to set the
value of a field of an instantiated class. It cannot be used in any
calculus. Example:<br/><br/><center id='center14858'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14856'
>(<font color="#1919af"><strong id='bold27660'
>module</strong></font> <font color="#1919af"><strong id='bold27662'
>obj-example</strong></font>
   (<font color="#1919af"><strong id='bold27664'
>export</strong></font> (<strong id='bold27666'
>class</strong> <font color="#1919af"><strong id='bold27667'
>c1</strong></font> a b o2<font color="#00cf00"><strong id='bold27669'
>::c2</strong></font>)
           (<strong id='bold27671'
>class</strong> c2 x y o1<font color="#00cf00"><strong id='bold27672'
>::c1</strong></font>)))<br/><br/>(co-instantiate ((o1 (<strong id='bold27674'
>instantiate</strong><font color="#00cf00"><strong id='bold27675'
>::c1</strong></font>
                        (a 10)
                        (b 20)
                        (o2 o2)))
                 (o2 (<strong id='bold27677'
>instantiate</strong><font color="#00cf00"><strong id='bold27678'
>::c2</strong></font>
                        (x 10)
                        (y 20)
                        (o1 o1))))
   (+ (c2-x (c1-o2 o1)) (c2-y (c1-o2 x))))
                                       =&gt; 30
</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="g14862" class="mark"></a><a name="duplicate::" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc14868" align="left" colspan="1"><strong id='bold14864'
>duplicate::</strong><em id='it14867'
><code id='code14866'
><em id='it14865'
>class</em></code> obj (ident value)...</em></td><td id="tc14869" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<a name="g14872" class="mark"></a>This forms allocates an instance of class <code id='code14875'
><em id='it14874'
>class</em></code>. The field
values of the new object are picked up from the field values of
the <code id='code14877'
><em id='it14876'
>old</em></code> object unless they are explicitly given in the parameter
list.<br/><br/>For instance:
<center id='center14883'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14881'
>(<strong id='bold27680'
>with-access</strong><font color="#00cf00"><strong id='bold27681'
>::point</strong></font> old (x)
   (make-point x 10))
</pre>
</td></tr>
</tbody></table></center>
is equivalent to:
<center id='center14888'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14886'
>(<strong id='bold27683'
>duplicate</strong><font color="#00cf00"><strong id='bold27684'
>::point</strong></font> old (y 10))
</pre>
</td></tr>
</tbody></table></center>

Indexed field must be provided with exactly two values. The first is the 
length of the indexed field and the second is the default value of each 
element of the indexed field.<br/><br/>Here is an example of creations and mutations of a complex object:
<center id='center14918'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14916'
>(<font color="#1919af"><strong id='bold27686'
>module</strong></font> <font color="#1919af"><strong id='bold27688'
>foo</strong></font>
   (<font color="#1919af"><strong id='bold27690'
>export</strong></font> (<strong id='bold27692'
>class</strong> <font color="#1919af"><strong id='bold27693'
>named-tab</strong></font>
              name<font color="#00cf00"><strong id='bold27695'
>::string</strong></font>
              (* els<font color="#00cf00"><strong id='bold27697'
>::int</strong></font>))))<br/><br/><font color="#ffa600"><em id='it27699'
>;; a function that prints a named-tab</em></font>
(<font color="#6959cf"><strong id='bold27701'
>define</strong></font> (<font color="#6959cf"><strong id='bold27703'
>print-tab</strong></font> tab)
   (display* (named-tab-name tab) <font color="red">&quot;: &quot;</font>)
   (<strong id='bold27706'
>let</strong> loop ((i (-fx (named-tab-els-len tab) 1)))
      (<strong id='bold27707'
>if</strong> (=fx i -1)
          (newline)
          (<strong id='bold27708'
>begin</strong>
             (display* #\( i 
                       <font color="red">&quot; &quot;</font>
                       (named-tab-els-ref tab i)
                       <font color="red">&quot;) &quot;</font>)
             (loop (-fx i 1))))))<br/><br/><font color="#ffa600"><em id='it27711'
>;; we allocate a named-tab object with</em></font>
<font color="#ffa600"><em id='it27713'
>;; 5 els, each of them initialized to 0</em></font>
(<font color="#6959cf"><strong id='bold27715'
>define</strong></font> <font color="#6959cf"><strong id='bold27717'
>a-tab</strong></font> (<strong id='bold27719'
>instantiate</strong><font color="#00cf00"><strong id='bold27720'
>::named-tab</strong></font>
                 (name <font color="red">&quot;example&quot;</font>)
                 (els 5 0)))<br/><br/><font color="#ffa600"><em id='it27723'
>;; we print its elements</em></font>
(print-tab a-tab) <br/><br/><font color="#ffa600"><em id='it27725'
>;; we change the values of the indexed field</em></font>
<font color="#ffa600"><em id='it27727'
>;; els by setting values from 0 to 4</em></font>
(<strong id='bold27729'
>let</strong> loop ((i (-fx (named-tab-els-len a-tab) 1)))
   (<strong id='bold27730'
>if</strong> (=fx i -1)
       'done
       (<strong id='bold27731'
>begin</strong>
          (named-tab-els-set! a-tab i i)
          (loop (-fx i 1)))))<br/><br/><font color="#ffa600"><em id='it27732'
>;; we re-print it</em></font>
(print-tab a-tab)
</pre>
</td></tr>
</tbody></table></center>

This will produce the following output:
<center id='center14921'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14919'
>example: (4 0) (3 0) (2 0) (1 0) (0 0) 
example: (4 4) (3 3) (2 2) (1 1) (0 0) 
</pre>
</td></tr>
</tbody></table></center>
</td></tr>
</tbody></table><br/>
</div><br>
<!-- Generic functions -->
<a name="Generic-functions"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">10.3 Generic functions</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Generic-functions" class="mark"></a><a name="g14924" class="mark"></a>
A generic function is a bag of specific functions known as methods. When
invoked on a Bigloo object, a generic function determines the class of the
discriminating variable (corresponding to the first argument of the generic
function) and invokes the appropriate method. Generic functions implement
single inheritance and each is defined using the <code id='code14926'
>define-generic</code> 
Bigloo syntax.<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g14929" class="mark"></a><a name="define-generic" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc14933" align="left" colspan="1"><strong id='bold14931'
>define-generic</strong><em id='it14932'
> (name arg...) default-body</em></td><td id="tc14934" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>

A generic function can be defined with a default body which will
be evaluated if no method can be found for the discriminating
variable. The default default-body signals an error.
</td></tr>
</tbody></table><br/>
As an example, here is a possible definition of the <code id='code14939'
>object-display</code> 
generic function:<br/><br/><center id='center14949'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14947'
>(<font color="#6959cf"><strong id='bold27734'
>define-generic</strong></font> (<font color="#6959cf"><strong id='bold27736'
>object-display</strong></font> obj<font color="#00cf00"><strong id='bold27738'
>::object</strong></font> . op)
   (<strong id='bold27740'
>let</strong> ((port (<strong id='bold27741'
>if</strong> (pair? op) 
                   (car op) 
                   (current-output-port))))
      (display <font color="red">&quot;#\|&quot;</font> port)
      (display (class-name (object-class obj)) port)
      (display <font color="red">&quot;\|&quot;</font> port)))
</pre>
</td></tr>
</tbody></table></center>

Methods can be defined to specialize a generic function and such
methods must have a
compatible variable list. That is, the first argument of the
method must be a sub-type (i.e. belong to a sub-class) of the
first argument of the generic function. Other formal parameters
must be of same types. Moreover, the result type of the method
must be a sub-type of the result of the generic function.<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g14952" class="mark"></a><a name="define-method" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc14956" align="left" colspan="1"><strong id='bold14954'
>define-method</strong><em id='it14955'
> (name arg...) body</em></td><td id="tc14957" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<a name="g14961" class="mark"></a><a name="call-next-method" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc14965" align="left" colspan="1"><strong id='bold14963'
>call-next-method</strong><em id='it14964'
></em></td><td id="tc14966" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
If there is no appropriate method, an error is signaled.<br/><br/>Methods can use the form <code id='code14970'
>(call-next-method)</code> to invoke the method
that would have been called if not present. The <code id='code14971'
>(call-next-method)</code>
cannot be used out of method definition.
example:
<center id='center14981'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog14979'
>(<font color="#6959cf"><strong id='bold27744'
>define-method</strong></font> (<font color="#6959cf"><strong id='bold27746'
>object-display</strong></font> p<font color="#00cf00"><strong id='bold27748'
>::person</strong></font> . op)
   (<strong id='bold27750'
>let</strong> ((port (<strong id='bold27751'
>if</strong> (pair? op) 
                   (car op) 
                   (current-output-port))))
      (fprint port <font color="red">&quot;firstname : &quot;</font> (person-fname p))
      (fprint port <font color="red">&quot;name      : &quot;</font> (person-name p))
      (fprint port <font color="red">&quot;sex       : &quot;</font> (person-sex p))
      p))
</pre>
</td></tr>
</tbody></table></center>
</td></tr>
</tbody></table><br/>
</div><br>
<!-- Widening and shrinking -->
<a name="Widening-and-shrinking"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">10.4 Widening and shrinking</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Widening-and-shrinking" class="mark"></a><a name="g14984" class="mark"></a>
Bigloo introduces a new kind of inheritance: <em id='emph14986'
>widening</em>. This allows an
object to be temporarily <em id='emph14987'
>widened</em> (that is transformed into an object
of another class, a <em id='emph14988'
>wide-class</em>) and then <em id='emph14989'
>shrink-ed</em> (that is
reshaped to its original class). This mechanism is very useful for
implementing short-term data storage. For instance, Bigloo compilation
passes are implemented using the <em id='emph14990'
>widening/shrinking</em> mechanism. On
entry to a pass, objects are widened with the specific pass fields and, on
exit from a pass, objects are shrunk in order to forget the information
related to this pass.<br/><br/>Only instances of <em id='emph14992'
>final classes</em> can be widened and objects can
only be widened in order to become instances of <em id='emph14993'
>wide classes</em>. 
Widening is performed by the <code id='code14994'
>widen!</code> syntax:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g14997" class="mark"></a><a name="widen!::" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15003" align="left" colspan="1"><strong id='bold14999'
>widen!::</strong><em id='it15002'
><code id='code15001'
><em id='it15000'
>wide-class</em></code> obj (id value) ...</em></td><td id="tc15004" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
<a name="g15007" class="mark"></a>
The object <code id='code15010'
><em id='it15009'
>obj</em></code> is widened to be instance of the wide class
<code id='code15012'
><em id='it15011'
>wide-class</em></code>. Fields values are either picked up from the
parameter list of the <code id='code15013'
>widen!</code> form or
from the default values in the declaration of the wide class.
</td></tr>
</tbody></table><br/>
Objects are shrunk using the <code id='code15016'
>shrink!</code> syntax:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15019" class="mark"></a><a name="shrink!" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15023" align="left" colspan="1"><strong id='bold15021'
>shrink!</strong><em id='it15022'
> obj</em></td><td id="tc15024" align="right" colspan="1">bigloo syntax</td></tr>
</tbody></table>
</td></tr>
</tbody></table><br/>
Here is a first example:
<center id='center15040'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15038'
>(<font color="#1919af"><strong id='bold27755'
>module</strong></font> <font color="#1919af"><strong id='bold27757'
>example</strong></font>
   (<strong id='bold27759'
>static</strong> (final-class point 
              (x (default 0))
              (y (default 0)))
           (<strong id='bold27760'
>wide-class</strong> named-point<font color="#00cf00"><strong id='bold27761'
>::point</strong></font> name)))<br/><br/>(<font color="#6959cf"><strong id='bold27763'
>define</strong></font> <font color="#6959cf"><strong id='bold27765'
>*point*</strong></font> (<strong id='bold27767'
>instantiate</strong><font color="#00cf00"><strong id='bold27768'
>::point</strong></font>))
</pre>
</td></tr>
</tbody></table></center>

Two classes have been declared and an instance <code id='code15041'
>*point*</code> of
<code id='code15042'
>point</code> has been allocated. For now, <code id='code15043'
>*point*</code> is an instance
of <code id='code15044'
>point</code> but not an instance of <code id='code15045'
>named-point</code> and this can
be checked by:
<center id='center15048'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15046'
>(print (named? *point*))           ==&gt; #t
(print (named-point? *point*))     ==&gt; #f
</pre>
</td></tr>
</tbody></table></center>

Now, we <em id='emph15049'
>widen</em> <code id='code15050'
>*point*</code>...
<center id='center15057'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15055'
>(<strong id='bold27770'
>let</strong> ((n-point (<strong id='bold27771'
>widen!</strong><font color="#00cf00"><strong id='bold27772'
>::named-point</strong></font> *point* 
                  (name <font color="red">&quot;orig&quot;</font>))))
</pre>
</td></tr>
</tbody></table></center>

And we check that now, <code id='code15058'
>n-point</code> is an instance of
<code id='code15059'
>named-point</code>. Since <code id='code15060'
>named-point</code> is a subclass of 
<code id='code15061'
>point</code>, <code id='code15062'
>n-point</code> still is an instance of <code id='code15063'
>point</code>.<br/><br/><center id='center15067'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15065'
>(print (named-point? n-point))  ==&gt; #t
(print (named? n-point))        ==&gt; #t
</pre>
</td></tr>
</tbody></table></center>
<br/><br/>Widening affects the objects themselves. It does not operate any
copy operation. Hence, <code id='code15069'
>*point*</code> and <code id='code15070'
>n-point</code> are <code id='code15071'
>eq?</code>.<br/><br/><center id='center15075'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15073'
>(print (eq? n-point *point*))   ==&gt; #t
</pre>
</td></tr>
</tbody></table></center>

To end this example, we <em id='emph15076'
>shrink</em> <code id='code15077'
>n-point</code> and check 
its class.
<center id='center15081'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15079'
>(<strong id='bold27775'
>shrink!</strong> n-point)
(print (named-point? *point*))) ==&gt; #f
</pre>
</td></tr>
</tbody></table></center>

Here is a more complex example:<br/><br/>We illustrate widening and shrinking using our ``wedding simulator''. 
First let us define three classes, <code id='code15083'
>person</code> (for man and woman), 
<code id='code15084'
>married-woman</code> and <code id='code15085'
>married-man</code>:
<center id='center15101'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15099'
>(<font color="#1919af"><strong id='bold27776'
>module</strong></font> <font color="#1919af"><strong id='bold27778'
>wedding</strong></font>
   (<strong id='bold27780'
>static</strong> (final-class person 
               name<font color="#00cf00"><strong id='bold27781'
>::string</strong></font>
               fname<font color="#00cf00"><strong id='bold27783'
>::string</strong></font>
               (sex<font color="#00cf00"><strong id='bold27785'
>::symbol</strong></font> read-only))
           (<strong id='bold27787'
>wide-class</strong> married-man<font color="#00cf00"><strong id='bold27788'
>::person</strong></font>
               mate<font color="#00cf00"><strong id='bold27790'
>::person</strong></font>)
           (<strong id='bold27792'
>wide-class</strong> married-woman<font color="#00cf00"><strong id='bold27793'
>::person</strong></font>
               maiden-name<font color="#00cf00"><strong id='bold27795'
>::string</strong></font>
               mate<font color="#00cf00"><strong id='bold27797'
>::person</strong></font>)))
</pre>
</td></tr>
</tbody></table></center>
As we can see people are allowed to change their name but not their sex.<br/><br/>The identity of a person can be printed as
<center id='center15112'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15110'
>(<font color="#6959cf"><strong id='bold27799'
>define-method</strong></font> (<font color="#6959cf"><strong id='bold27801'
>object-display</strong></font> p<font color="#00cf00"><strong id='bold27803'
>::person</strong></font> . op)
   (<strong id='bold27805'
>with-access</strong><font color="#00cf00"><strong id='bold27806'
>::person</strong></font> p (name fname sex)
      (print <font color="red">&quot;firstname : &quot;</font> fname)
      (print <font color="red">&quot;name      : &quot;</font> name)
      (print <font color="red">&quot;sex       : &quot;</font> sex)
      p))
</pre>
</td></tr>
</tbody></table></center>

A married woman's identity is printed by (we suppose an equivalent method 
definition for married-man)
<center id='center15121'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15119'
>(<font color="#6959cf"><strong id='bold27811'
>define-method</strong></font> (<font color="#6959cf"><strong id='bold27813'
>object-display</strong></font> p<font color="#00cf00"><strong id='bold27815'
>::married-woman</strong></font> . op)
   (<strong id='bold27817'
>with-access</strong><font color="#00cf00"><strong id='bold27818'
>::married-woman</strong></font> p (name fname sex mate)
      (call-next-method)
      (print <font color="red">&quot;married to: &quot;</font> (person-fname mate) 
                            <font color="red">&quot; &quot;</font> 
                            (person-name mate))
      p))
</pre>
</td></tr>
</tbody></table></center>

We create a person with the <code id='code15122'
>birth</code> function:
<center id='center15130'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15128'
>(<font color="#6959cf"><strong id='bold27822'
>define</strong></font> (<font color="#6959cf"><strong id='bold27824'
>birth</strong></font> name<font color="#00cf00"><strong id='bold27826'
>::string</strong></font> fname<font color="#00cf00"><strong id='bold27828'
>::string</strong></font> sex)
   [assert (sex) (memq sex '(male female))]
   (<strong id='bold27830'
>instantiate</strong><font color="#00cf00"><strong id='bold27831'
>::person</strong></font> 
      (name name)
      (fname fname)
      (sex sex)))
</pre>
</td></tr>
</tbody></table></center>

We celebrate a wedding using the <code id='code15131'
>get-married!</code> function:
<center id='center15146'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15144'
>(<font color="#6959cf"><strong id='bold27833'
>define</strong></font> (<font color="#6959cf"><strong id='bold27835'
>get-married!</strong></font> woman<font color="#00cf00"><strong id='bold27837'
>::person</strong></font> man<font color="#00cf00"><strong id='bold27839'
>::person</strong></font>)
   (<strong id='bold27841'
>if</strong> (not (and (eq? (person-sex woman) 'female)
                 (eq? (person-sex man) 'male)))
       (<font color="red"><strong id='bold27842'
>error</strong></font> <font color="red">&quot;get-married&quot;</font> 
              <font color="red">&quot;Illegal wedding&quot;</font> 
              (cons woman man))
       (<strong id='bold27846'
>let*</strong> ((mname (person-name woman))
              (wife  (<strong id='bold27847'
>widen!</strong><font color="#00cf00"><strong id='bold27848'
>::married-woman</strong></font> woman
                      (maiden-name mname)
                      (mate man))))
          (person-name-set! wife (person-name man))
          (<strong id='bold27850'
>widen!</strong><font color="#00cf00"><strong id='bold27851'
>::married-man</strong></font> man
             (mate woman)))))
</pre>
</td></tr>
</tbody></table></center>

We can check if two people are married by
<center id='center15152'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15150'
>(<font color="#6959cf"><strong id='bold27853'
>define</strong></font> (<font color="#6959cf"><strong id='bold27855'
>couple?</strong></font> woman<font color="#00cf00"><strong id='bold27857'
>::person</strong></font> man<font color="#00cf00"><strong id='bold27859'
>::person</strong></font>)
   (and (married-woman? woman)
        (married-man? man)
        (eq? (married-woman-mate woman) man)
        (eq? (married-man-mate man) woman)))
</pre>
</td></tr>
</tbody></table></center>

Now let us study the life a <code id='code15153'
>Junior</code> <code id='code15154'
>Jones</code> and
<code id='code15155'
>Pamela</code> <code id='code15156'
>Smith</code>. Once upon a time...
<center id='center15165'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15163'
>(<font color="#6959cf"><strong id='bold27861'
>define</strong></font> <font color="#6959cf"><strong id='bold27863'
>*junior*</strong></font> (birth <font color="red">&quot;Jones&quot;</font> <font color="red">&quot;Junior&quot;</font> 'male))
(<font color="#6959cf"><strong id='bold27867'
>define</strong></font> <font color="#6959cf"><strong id='bold27869'
>*pamela*</strong></font> (birth <font color="red">&quot;Smith&quot;</font> <font color="red">&quot;Pamela&quot;</font> 'female))
</pre>
</td></tr>
</tbody></table></center>

Later on, they met each other and ... they got married:
<center id='center15170'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15168'
>(<font color="#6959cf"><strong id='bold27873'
>define</strong></font> <font color="#6959cf"><strong id='bold27875'
>*old-boy-junior*</strong></font> *junior*)
(<font color="#6959cf"><strong id='bold27877'
>define</strong></font> <font color="#6959cf"><strong id='bold27879'
>*old-girl-pamela*</strong></font> *pamela*)
(get-married! *pamela* *junior*)
</pre>
</td></tr>
</tbody></table></center>

This union can be checked:
<center id='center15173'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15171'
>(couple? *pamela* *junior*)               
   =&gt; #t
</pre>
</td></tr>
</tbody></table></center>

We can look at the new identity of <code id='code15174'
>*pamela*</code>
<center id='center15177'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15175'
>(print *pamela*)
   -| name      : Jones
      firstname : Pamela
      sex       : FEMALE
      married to: Junior Jones
</pre>
</td></tr>
</tbody></table></center>

But <code id='code15178'
>*pamela*</code> and <code id='code15179'
>*junior*</code> still are the same persons:
<center id='center15182'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15180'
>(print (eq? *old-boy-junior* *junior*))   =&gt; #t
(print (eq? *old-girl-pamela* *pamela*))  =&gt; #t
</pre>
</td></tr>
</tbody></table></center>

Unfortunately all days are not happy days. After having been married
<code id='code15183'
>*pamela*</code> and <code id='code15184'
>*junior*</code> have divorced:
<center id='center15199'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15197'
>(<font color="#6959cf"><strong id='bold27881'
>define</strong></font> (<font color="#6959cf"><strong id='bold27883'
>divorce!</strong></font> woman<font color="#00cf00"><strong id='bold27885'
>::person</strong></font> man<font color="#00cf00"><strong id='bold27887'
>::person</strong></font>)
   (<strong id='bold27889'
>if</strong> (not (couple? woman man))
       (<font color="red"><strong id='bold27890'
>error</strong></font> <font color="red">&quot;divorce!&quot;</font>
              <font color="red">&quot;Illegal divorce&quot;</font>
              (cons woman man))
       (<strong id='bold27894'
>let</strong> ((mname (married-woman-maiden-name 
                      woman)))
          (<strong id='bold27895'
>begin</strong>
             (<strong id='bold27896'
>shrink!</strong> woman)
             (person-name-set! woman mname))
          (<strong id='bold27897'
>shrink!</strong> man))))<br/><br/>(divorce! *pamela* *junior*)
</pre>
</td></tr>
</tbody></table></center>

We can look at the new identity of <code id='code15200'
>*pamela*</code>
<center id='center15203'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15201'
>(print *pamela*)
   -| name      : Smith
      firstname : Pamela
      sex       : FEMALE
</pre>
</td></tr>
</tbody></table></center>

And <code id='code15204'
>*pamela*</code> and <code id='code15205'
>*junior*</code> still are the same persons:
<center id='center15208'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15206'
>(print (eq? *old-boy-junior* *junior*))   =&gt; #t
(print (eq? *old-girl-pamela* *pamela*))  =&gt; #t
</pre>
</td></tr>
</tbody></table></center>

</div><br>
<!-- Object library -->
<a name="Object-library"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">10.5 Object library</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Object-library" class="mark"></a><a name="g15209" class="mark"></a>
<!-- Classes handling -->
<a name="Classes-handling"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">10.5.1 Classes handling</font>
</h3></td></tr></table>
</div><div class="subsection">
No type denotes Bigloo's classes. These objects are handled
by the following library functions:<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15213" class="mark"></a><a name="find-class" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15217" align="left" colspan="1"><strong id='bold15215'
>find-class</strong><em id='it15216'
> symbol</em></td><td id="tc15218" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns, if any, the class named <code id='code15222'
><em id='it15221'
>symbol</em></code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15226" class="mark"></a><a name="class?" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15230" align="left" colspan="1"><strong id='bold15228'
>class?</strong><em id='it15229'
> obj</em></td><td id="tc15231" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns <code id='code15234'
>#t</code> if and only if <code id='code15236'
><em id='it15235'
>obj</em></code> is a class.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15240" class="mark"></a><a name="class-super" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15244" align="left" colspan="1"><strong id='bold15242'
>class-super</strong><em id='it15243'
> class</em></td><td id="tc15245" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the <em id='emph15248'
>super-class</em> of <code id='code15250'
><em id='it15249'
>class</em></code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15254" class="mark"></a><a name="class-subclasses" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15258" align="left" colspan="1"><strong id='bold15256'
>class-subclasses</strong><em id='it15257'
> class</em></td><td id="tc15259" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the <em id='emph15262'
>subclasses</em> of <code id='code15264'
><em id='it15263'
>class</em></code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15268" class="mark"></a><a name="class-name" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15272" align="left" colspan="1"><strong id='bold15270'
>class-name</strong><em id='it15271'
> class</em></td><td id="tc15273" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the name (a symbol) of <code id='code15277'
><em id='it15276'
>class</em></code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15281" class="mark"></a><a name="object-constructor" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15285" align="left" colspan="1"><strong id='bold15283'
>object-constructor</strong><em id='it15284'
> class</em></td><td id="tc15286" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns <code id='code15290'
><em id='it15289'
>class</em></code>'s constructor.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15294" class="mark"></a><a name="object-class" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15298" align="left" colspan="1"><strong id='bold15296'
>object-class</strong><em id='it15297'
> object</em></td><td id="tc15299" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the class that <code id='code15303'
><em id='it15302'
>object</em></code> belongs to.
</td></tr>
</tbody></table><br/>
</div>
<!-- Object handling -->
<a name="Object-handling"></a>
<div class="subsection-atitle"><table width="100%"><tr><td bgcolor="#ffffff"><h3><font color="#8381de">10.5.2 Object handling</font>
</h3></td></tr></table>
</div><div class="subsection">
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15307" class="mark"></a><a name="wide-object?" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15311" align="left" colspan="1"><strong id='bold15309'
>wide-object?</strong><em id='it15310'
> object</em></td><td id="tc15312" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns <code id='code15315'
>#t</code> if <code id='code15317'
><em id='it15316'
>object</em></code> is a wide object otherwise it returns 
<code id='code15318'
>#f</code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15322" class="mark"></a><a name="object-display" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15326" align="left" colspan="1"><strong id='bold15324'
>object-display</strong><em id='it15325'
> object [port]</em></td><td id="tc15327" align="right" colspan="1">bigloo generic</td></tr>
</tbody></table>
This generic function is invoked by <code id='code15330'
>display</code> to display objects.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15334" class="mark"></a><a name="object-write" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15338" align="left" colspan="1"><strong id='bold15336'
>object-write</strong><em id='it15337'
> object [port]</em></td><td id="tc15339" align="right" colspan="1">bigloo generic</td></tr>
</tbody></table>
This generic function is invoked by <code id='code15342'
>write</code> to write objects.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15346" class="mark"></a><a name="object->struct" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15350" align="left" colspan="1"><strong id='bold15348'
>object-&gt;struct</strong><em id='it15349'
> object</em></td><td id="tc15351" align="right" colspan="1">bigloo generic</td></tr>
</tbody></table>
<a name="g15355" class="mark"></a><a name="struct->object" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15359" align="left" colspan="1"><strong id='bold15357'
>struct-&gt;object</strong><em id='it15358'
> struct</em></td><td id="tc15360" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
These functions converts objects into Scheme structures and vice-versa.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15366" class="mark"></a><a name="object-equal?" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15370" align="left" colspan="1"><strong id='bold15368'
>object-equal?</strong><em id='it15369'
> object obj</em></td><td id="tc15371" align="right" colspan="1">bigloo generic</td></tr>
</tbody></table>
This generic function is invoked by <code id='code15374'
>equal?</code> when the first argument
is an instance of <code id='code15375'
>object</code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15380" align="left" colspan="1"><strong id='bold15378'
>object-hashnumber</strong><em id='it15379'
> object</em></td><td id="tc15381" align="right" colspan="1">bigloo generic</td></tr>
</tbody></table>
This generic function returns an hash number of <code id='code15385'
><em id='it15384'
>object</em></code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15389" class="mark"></a><a name="is-a?" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15393" align="left" colspan="1"><strong id='bold15391'
>is-a?</strong><em id='it15392'
> obj class</em></td><td id="tc15394" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns <code id='code15397'
>#t</code> if <code id='code15399'
><em id='it15398'
>obj</em></code> belongs to <code id='code15401'
><em id='it15400'
>class</em></code> otherwise it
returns <code id='code15402'
>#f</code>.
</td></tr>
</tbody></table><br/>
</div>
</div><br>
<!-- Object serialization -->
<a name="Object-serialization"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">10.6 Object serialization</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Object-serialization" class="mark"></a><a name="g15405" class="mark"></a>
Objects can be <em id='emph15407'
>serialized</em> and <em id='emph15408'
>un-serialized</em> using
the regular <code id='code15409'
>string-&gt;obj</code> and <code id='code15410'
>obj-&gt;string</code>
functions. Objects can be stored on disk and restored from disk
by the use of the <code id='code15411'
>output-obj</code> and <code id='code15412'
>input-obj</code>
functions.<br/><br/>In addition to this standard serialization mechanism, custom object
serializers and un-serializers can be specified by the means of the
<code id='code15414'
>register-class-serialization!</code> function (see Section
<a href="bigloo-7.html#Serialization" class="inbound">Serialization</a>.<br/><br/></div><br>
<!-- Equality -->
<a name="Equality"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">10.7 Equality</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Equality" class="mark"></a><a name="g15416" class="mark"></a>
Two objects can be compared with the <code id='code15418'
>equal?</code> function. Two object
are equal if and only if they belong to a same class, all their field
values are equal and all their super class's field values are equal.<br/><br/></div><br>
<!-- Introspection -->
<a name="Introspection"></a>
<div class="section-atitle"><table width="100%"><tr><td bgcolor="#dedeff"><h3><font color="black">10.8 Introspection</font>
</h3></td></tr></table>
</div><div class="section">
<a name="Introspection" class="mark"></a><a name="g15420" class="mark"></a>
Bigloo provides the programmer with some object introspection facilities.
See section see <a href="bigloo-11.html#Object-library" class="inbound">Object library</a> for information on classes and
objects handling. Introspection facilities are, by default, available
for all classes. However, in order to shrink the code size generation,
it may be useful to disable class introspection. This decision can be
taken on a per class basis (i.e., one class may be provided with
introspection facilities while another one is not). The compiler
option <code id='code15422'
>-fno-reflection</code> 
(see Chapter <a href="bigloo-31.html#Compiler-Description" class="inbound">Compiler Description</a>) prevents the
compiler to generate the code required for introspecting the classes
defined in the compiled module.<br/><br/><table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15425" class="mark"></a><a name="class-fields" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15429" align="left" colspan="1"><strong id='bold15427'
>class-fields</strong><em id='it15428'
> class</em></td><td id="tc15430" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the a description of the fields of <code id='code15434'
><em id='it15433'
>class</em></code>. This description
is a list of field descriptions where each field description can be accessed by
the means of the following library functions. The fields are those 
<em id='emph15435'
>directly</em> defined in <code id='code15437'
><em id='it15436'
>class</em></code>. That is <code id='code15438'
>class-fields</code> does not
return fields defined in super classes of <code id='code15440'
><em id='it15439'
>class</em></code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15444" class="mark"></a><a name="class-all-fields" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15448" align="left" colspan="1"><strong id='bold15446'
>class-all-fields</strong><em id='it15447'
> class</em></td><td id="tc15449" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the a description of the fields of <code id='code15453'
><em id='it15452'
>class</em></code>. This description
is a list of field descriptions where each field description can be accessed by
the means of the following library functions. By contrast with 
<code id='code15454'
>class-fields</code>, this function returns fields that are also defined in
the super classes of <code id='code15456'
><em id='it15455'
>class</em></code>.
in th
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15460" class="mark"></a><a name="find-class-field" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15464" align="left" colspan="1"><strong id='bold15462'
>find-class-field</strong><em id='it15463'
> class symbol</em></td><td id="tc15465" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the field named <code id='code15469'
><em id='it15468'
>symbol</em></code> from class <code id='code15471'
><em id='it15470'
>class</em></code>. Returns 
<code id='code15472'
>#f</code> is such a field does not exist.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15476" class="mark"></a><a name="class-field?" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15480" align="left" colspan="1"><strong id='bold15478'
>class-field?</strong><em id='it15479'
> obj</em></td><td id="tc15481" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns #t if <code id='code15485'
><em id='it15484'
>obj</em></code> is a class field descriptor. Otherwise returns #f.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15489" class="mark"></a><a name="class-field-name" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15493" align="left" colspan="1"><strong id='bold15491'
>class-field-name</strong><em id='it15492'
> field</em></td><td id="tc15494" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the name of the <code id='code15498'
><em id='it15497'
>field</em></code>. The name is a symbol.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15502" class="mark"></a><a name="class-field-indexed?" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15506" align="left" colspan="1"><strong id='bold15504'
>class-field-indexed?</strong><em id='it15505'
> field</em></td><td id="tc15507" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns <code id='code15510'
>#t</code> if the described field is indexed and <code id='code15511'
>#f</code> otherwise.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15515" class="mark"></a><a name="class-field-accessor" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15519" align="left" colspan="1"><strong id='bold15517'
>class-field-accessor</strong><em id='it15518'
> field</em></td><td id="tc15520" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns a procedure of one argument. Applying this function to an object
returns the value of the field described by <code id='code15524'
><em id='it15523'
>field</em></code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15528" class="mark"></a><a name="class-field-len-accessor" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15532" align="left" colspan="1"><strong id='bold15530'
>class-field-len-accessor</strong><em id='it15531'
> field</em></td><td id="tc15533" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
A one argument function is returned. Applying this function to an object
returns the length value of the field described by field. It is an error
to apply <code id='code15536'
>class-field-len-accessor</code> to a non-indexed field.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15540" class="mark"></a><a name="class-field-mutable?" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15544" align="left" colspan="1"><strong id='bold15542'
>class-field-mutable?</strong><em id='it15543'
> field</em></td><td id="tc15545" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns <code id='code15548'
>#t</code> if the described field is mutable and <code id='code15549'
>#f</code> otherwise.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15553" class="mark"></a><a name="class-field-mutator" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15557" align="left" colspan="1"><strong id='bold15555'
>class-field-mutator</strong><em id='it15556'
> field</em></td><td id="tc15558" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns a procedure of three, or two, arguments depending on whether
the field is indexed or not. Applying this function to an object
changes the value of the field described by <code id='code15562'
><em id='it15561'
>field</em></code>. It is an
error to apply <code id='code15563'
>class-field-mutator</code> to an immutable field.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15567" class="mark"></a><a name="class-field-info" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15571" align="left" colspan="1"><strong id='bold15569'
>class-field-info</strong><em id='it15570'
> field</em></td><td id="tc15572" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the information associated to <code id='code15576'
><em id='it15575'
>field</em></code> (this the class declaration
<code id='code15577'
>info</code> attribute).
</td></tr>
</tbody></table><br/><br/><br/>For means of an example, here is a possible implementation of the
<code id='code15581'
>equal?</code> test for objects:<br/><br/><center id='center15599'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15597'
>(<font color="#6959cf"><strong id='bold27898'
>define</strong></font> (<font color="#6959cf"><strong id='bold27900'
>object-equal?</strong></font> obj1 obj2)
   (<font color="#6959cf"><strong id='bold27902'
>define</strong></font> (<font color="#6959cf"><strong id='bold27904'
>class-field-equal?</strong></font> fd)
      (<strong id='bold27906'
>let</strong> ((get-value (class-field-accessor fd)))
         (<strong id='bold27907'
>if</strong> (not (class-field-indexed? fd))
             (equal? (get-value obj1)
                     (get-value obj2))
             (<strong id='bold27908'
>let*</strong> ((len (class-field-len-accessor
                          fd)))
                    (len1 (len obj1))
                    (len2 (len obj2)))
                (and (=fx len1 len2)
                     (<strong id='bold27909'
>let</strong> loop ((i 0))
                        (<strong id='bold27910'
>cond</strong>
                           ((=fx i len1)
                            #t)
                           ((equal?
                             (get-value obj1 i)
                             (get-value obj2 i))
                            (loop (+fx i 1)))
                           (else
                            #f))))))))
   (<strong id='bold27911'
>let</strong> ((class1 (object-class obj1))
         (class2 (object-class obj2)))
      (<strong id='bold27912'
>cond</strong>
         ((not (eq? class1 class2))
          #f)
         (else
          (<strong id='bold27913'
>let</strong> loop ((fields (class-fields class1))
                     (<strong id='bold27914'
>class</strong>  class1))
             (<strong id='bold27915'
>cond</strong>
                ((null? fields)
                 (<strong id='bold27916'
>let</strong> ((super (class-super class)))
                    (<strong id='bold27917'
>if</strong> (class? super)
                        (loop (class-fields super)
                              super)
                        #t)))
                ((class-field-equal? (car fields))
                 (loop (cdr fields) class))
                (else
                 #f)))))))
</pre>
</td></tr>
</tbody></table></center>

<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15601" class="mark"></a><a name="class-creator" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15605" align="left" colspan="1"><strong id='bold15603'
>class-creator</strong><em id='it15604'
> class</em></td><td id="tc15606" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the creator for <code id='code15610'
><em id='it15609'
>class</em></code>. The creator is a function for which
the arity depends on the number of slots the class provides 
(see Section see <a href="bigloo-11.html#Creating-and-accessing-objects" class="inbound">Creating and accessing objects</a>).<br/><br/>When an instance is allocated by the means of the <code id='code15612'
>class-creator</code>, as
for direct instantiation, the class constructor is 
<em id='emph15613'
>automatically</em> invoked.
Example:
<center id='center15633'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15631'
>(<font color="#1919af"><strong id='bold27918'
>module</strong></font> <font color="#1919af"><strong id='bold27920'
>foo</strong></font>
   (main main)
   (<strong id='bold27922'
>static</strong> (<strong id='bold27923'
>class</strong> c1 (c1-constructor))))<br/><br/>(<font color="#6959cf"><strong id='bold27924'
>define</strong></font> <font color="#6959cf"><strong id='bold27926'
>c1-constructor</strong></font>
   (<strong id='bold27928'
>let</strong> ((count 0))
      (<strong id='bold27929'
>lambda</strong> (inst)
	 (<strong id='bold27930'
>set!</strong> count (+ 1 count))
	 (print <font color="red">&quot;creating instance: &quot;</font> count)
	 inst)))<br/><br/>(<font color="#6959cf"><strong id='bold27932'
>define</strong></font> (<font color="#6959cf"><strong id='bold27934'
>main</strong></font> argv)
   (<strong id='bold27936'
>let</strong> ((o1 (<strong id='bold27937'
>instantiate</strong><font color="#00cf00"><strong id='bold27938'
>::c1</strong></font>))
	 (o2 (<strong id='bold27940'
>instantiate</strong><font color="#00cf00"><strong id='bold27941'
>::c1</strong></font>))
	 (o3 ((class-creator c1))))
      'done))
   -| creating instance: 1
      creating instance: 2
      creating instance: 3
</pre>
</td></tr>
</tbody></table></center>

For each indexed field, two values must be sent to the function returned
by <code id='code15634'
>class-creator</code>. The first value denotes the size of the indexed
field. The second value denotes the initial values of the fields. For instance:
<center id='center15644'
><table cellspacing="0" class="color" cellpadding="0" width="95%"><tbody>
<tr><td bgcolor="#ffffcc"><pre class="prog" id='prog15642'
>(<font color="#1919af"><strong id='bold27943'
>module</strong></font> <font color="#1919af"><strong id='bold27945'
>example</strong></font>
   (<font color="#1919af"><strong id='bold27947'
>export</strong></font> (<strong id='bold27949'
>class</strong> <font color="#1919af"><strong id='bold27950'
>point</strong></font> x y (* z))))<br/><br/>(<strong id='bold27952'
>let</strong> ((create (class-creator point)))
   (print (create 10 23 5 3)))
</pre>
</td></tr>
</tbody></table></center>

Produces
  -| #|POINT [X: 10] [Y: 23] [Z: 3 3 3 3 3]|
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15648" class="mark"></a><a name="class-nil" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15652" align="left" colspan="1"><strong id='bold15650'
>class-nil</strong><em id='it15651'
> class</em></td><td id="tc15653" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the NIL creator for <code id='code15657'
><em id='it15656'
>class</em></code>.
</td></tr>
</tbody></table><br/>
<table cellspacing="0" class="frame" cellpadding="10" border="1" width="100%"><tbody>
<tr><td><a name="g15661" class="mark"></a><a name="class-predicate" class="mark"></a><table width="100%" style="border-collapse: collapse;" frame="void" rules="none"><tbody>
<tr><td id="tc15665" align="left" colspan="1"><strong id='bold15663'
>class-predicate</strong><em id='it15664'
> class</em></td><td id="tc15666" align="right" colspan="1">bigloo procedure</td></tr>
</tbody></table>
Returns the predicate for <code id='code15670'
><em id='it15669'
>class</em></code>. This predicate returns <code id='code15671'
>#t</code>
when applied to object of type <code id='code15673'
><em id='it15672'
>class</em></code>. It returns <code id='code15674'
>#f</code> otherwise.
</td></tr>
</tbody></table><br/>

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