Commit b6225f44 authored by Marco Antoniotti's avatar Marco Antoniotti 💬
Browse files

Documentation updated.

parent 27b617a2
......@@ -129,16 +129,76 @@ discriminates on <code>eql</code> specializers on the head of the type
specifier.
</p>
<h2>Defining Methods to Handle <code>structure-class</code> Classes</h2>
<h2>Defining Methods to Handle <code>structure-class</code>
Classes</h2>
<p>The main problem that any implementation of the <b>NEW</b> API must
face is how to deal with <code>structure-class</code>es. The CL
specification does not make provisions for ways to fetch the
constructors of a DEFSTRUCT, which can be many.</p>
<p>The <b>NEW</b> API provides two ways to deal with such a problem:
(1) by introducing a modicum of new "syntax" that can be used to
circumvent the problem, and (2) by providing a way to <em>record</em>
the DEFSTRUCT constructors.
<h3>Extended "syntax" for <code>structure-class</code> and
<code>standard-class</code></h3>
<p>In order to provide a way to specify the "constructor" (and
therefore the standard one) in a call to <b><code>new</code></b> or
<b><code>newq</code></b> for a <code>structure-class</code> the
following syntax is introduced to specify a "pseudo type" clearly
identifying strucutre types (and, simmetrically, class types); in some
circuitous way this is akin to the C++ <code>typename</code> keyword.
<pre>
'(' <span style="color: red">structure</span> <i>&lt;structure type designator&gt;</i> [ <span style="color: red">by</span> <i>&lt;constructor&gt;</i> ] ')'
'(' <span style="color: red">class</span> <i>&lt;class designator&gt;</i> [ <span style="color: red">by</span> <i>&lt;constructor&gt;</i> ] ')'
</pre>
<h4>Example</h4>
<p>
<pre>
cl-prompt&gt; <b>(defstruct foo a s d)</b>
<i>FOO</i>
cl-prompt&gt; <b>(new '(<span style="color: red">structure</span> foo) :s 42)</b>
<i>#S(FOO :A NIL :S 42 :D NIL)</i>
cl-prompt&gt; <b>(defstruct (bar (:constructor <span style="color: blue">baryfy</span> (a s))
(:constructor <span style="color: blue">babar</span> (a &amp;optional (d (+1 a)))))
a s d)</b>
<i>FOO</i>
cl-prompt&gt; <b>(new '(<span style="color: red">structure</span> bar <span style="color: red">:by</span> <span style="color: blue">baryfy</span>) "QWE" "RTY")</b>
<i>#S(FOO :A "QWE" :S "RTY" :D NIL)</i>
cl-prompt&gt; <b>(newq (<span style="color: red">structure</span> bar <span style="color: red">:by</span> <span style="color: blue">babar</span>) 42)</b>
<i>#S(FOO :A 42 :S NIL :D 43)</i>
cl-prompt&gt; <b>(defclass baz () ())</b>
<i>BAZ</i>
cl-prompt&gt; <b>(newq (<span style="color: red">class</span> BAZ))</b>
<i>#&lt;BAZ 42&gt;</i>
</pre>
<h3><em>Recording</em> <code>structure-class</code> constructors</h3>
<p>While implementations must have a "generic" structure constructor
to deal with the <code>#S(STRUC-CLASS-NAME ...)</code> syntax, alas,
such functionality is not portably advertised. Because of this fact,
in order to allow the "plain" use of constructors (i.e., without the
wrapping <code>(structure <i>&lt;s&gt;</i>)</code>),
<code>new</code> must rely on an explicit "recording" of a constructor
for the structure, lest redefining the macro DEFSTRUCT. In order to
register a constructor for the benefit of <code>new</code> the
......@@ -146,7 +206,7 @@ function <code>register-structure-constructor</code> is thus
provided.
</p>
<h3>Example</h3>
<h4>Example</h4>
<p>
<pre>
......@@ -231,7 +291,7 @@ library code the scariest extra disclaimer you can think of.
-->
<div class="copyright">
<!-- hhmts start --> Last modified: Tue Jan 18 12:52:11 CET 2011 <!-- hhmts end --><br>
<!-- hhmts start --> Last modified: Wed Mar 9 16:43:12 CET 2011 <!-- hhmts end --><br>
&copy; 2010-2011, Marco Antoniotti, all rights reserved.
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment