Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
new-op
new-op
Commits
b6225f44
Commit
b6225f44
authored
Mar 09, 2011
by
Marco Antoniotti
💬
Browse files
Documentation updated.
parent
27b617a2
Changes
1
Hide whitespace changes
Inline
Side-by-side
docs/html/intro.html
View file @
b6225f44
...
...
@@ -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>
<
structure type designator
>
</i>
[
<span
style=
"color: red"
>
by
</span>
<i>
<
constructor
>
</i>
] ')'
'('
<span
style=
"color: red"
>
class
</span>
<i>
<
class designator
>
</i>
[
<span
style=
"color: red"
>
by
</span>
<i>
<
constructor
>
</i>
] ')'
</pre>
<h4>
Example
</h4>
<p>
<pre>
cl-prompt
>
<b>
(defstruct foo a s d)
</b>
<i>
FOO
</i>
cl-prompt
>
<b>
(new '(
<span
style=
"color: red"
>
structure
</span>
foo) :s 42)
</b>
<i>
#S(FOO :A NIL :S 42 :D NIL)
</i>
cl-prompt
>
<b>
(defstruct (bar (:constructor
<span
style=
"color: blue"
>
baryfy
</span>
(a s))
(:constructor
<span
style=
"color: blue"
>
babar
</span>
(a
&
optional (d (+1 a)))))
a s d)
</b>
<i>
FOO
</i>
cl-prompt
>
<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
>
<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
>
<b>
(defclass baz () ())
</b>
<i>
BAZ
</i>
cl-prompt
>
<b>
(newq (
<span
style=
"color: red"
>
class
</span>
BAZ))
</b>
<i>
#
<
BAZ 42
>
</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>
<
s
>
</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>
<h
3
>
Example
</h
3
>
<h
4
>
Example
</h
4
>
<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
:1
1
CET 2011
<!-- hhmts end -->
<br>
<!-- hhmts start -->
Last modified:
Wed Mar 9 16:43
:1
2
CET 2011
<!-- hhmts end -->
<br>
©
2010-2011, Marco Antoniotti, all rights reserved.
</div>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment