99 lines
4.7 KiB
HTML
99 lines
4.7 KiB
HTML
![]() |
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
|
||
|
<!Converted with LaTeX2HTML 0.6.5 (Tue Nov 15 1994) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
|
||
|
<HEAD>
|
||
|
<TITLE>19.7.3. Other Aspects of Explicitly Specified Structures</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Other Aspects of Explicitly Specified Structures">
|
||
|
<meta name="keywords" value="clm">
|
||
|
<meta name="resource-type" value="document">
|
||
|
<meta name="distribution" value="global">
|
||
|
<P>
|
||
|
<b>Common Lisp the Language, 2nd Edition</b>
|
||
|
<BR> <HR><A NAME=tex2html3749 HREF="node179.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3747 HREF="node175.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3743 HREF="node177.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3751 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3752 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html3750 HREF="node179.html"> The Evaluator</A>
|
||
|
<B>Up:</B> <A NAME=tex2html3748 HREF="node175.html"> Structures of Explicitly </A>
|
||
|
<B> Previous:</B> <A NAME=tex2html3744 HREF="node177.html"> Named Structures</A>
|
||
|
<HR> <P>
|
||
|
<H2><A NAME=SECTION002373000000000000000>19.7.3. Other Aspects of Explicitly Specified Structures</A></H2>
|
||
|
<P>
|
||
|
<A NAME=DEFSTRUCTINITIALOFFSET>The</A>
|
||
|
<tt>:initial-offset</tt> option allows one
|
||
|
to specify that slots be allocated beginning at a representational
|
||
|
element other than the first. For example, the form
|
||
|
<P><pre>
|
||
|
(defstruct (binop (:type list) (:initial-offset 2))
|
||
|
(operator '? :type symbol)
|
||
|
operand-1
|
||
|
operand-2)
|
||
|
</pre><P>
|
||
|
would result in the following behavior for <tt>make-binop</tt>:
|
||
|
<P><pre>
|
||
|
(make-binop :operator '+ :operand-1 'x :operand-2 5)
|
||
|
=> (nil nil + x 5) <BR><BR>(make-binop :operand-2 4 :operator '*)
|
||
|
=> (nil nil * <tt>nil</tt> 4)
|
||
|
</pre><P>
|
||
|
The selectors
|
||
|
<tt>binop-operator</tt>, <tt>binop-operand-1</tt>,
|
||
|
and <tt>binop-operand-2</tt> would be essentially equivalent to <tt>caddr</tt>,
|
||
|
<tt>cadddr</tt>, and <tt>car</tt> of <tt>cddddr</tt>, respectively.
|
||
|
Similarly, the form
|
||
|
<P><pre>
|
||
|
(defstruct (binop (:type list) :named (:initial-offset 2))
|
||
|
(operator '? :type symbol)
|
||
|
operand-1
|
||
|
operand-2)
|
||
|
</pre><P>
|
||
|
would result in the following behavior for <tt>make-binop</tt>:
|
||
|
<P><pre>
|
||
|
(make-binop :operator '+ :operand-1 'x :operand-2 5)
|
||
|
=> (nil nil binop + x 5)
|
||
|
|
||
|
(make-binop :operand-2 4 :operator '*)
|
||
|
=> (nil nil binop * <tt>nil</tt> 4)
|
||
|
</pre><P>
|
||
|
<P>
|
||
|
If the <tt>:include</tt> is used with the <tt>:type</tt>
|
||
|
option, then the effect is first to skip over as many representation
|
||
|
elements as needed to represent the included structure, then to
|
||
|
skip over any additional elements specified by the <tt>:initial-offset</tt>
|
||
|
option, and then to begin allocation of elements from that point.
|
||
|
For example:
|
||
|
<P><pre>
|
||
|
(defstruct (binop (:type list) :named (:initial-offset 2))
|
||
|
(operator '? :type symbol)
|
||
|
operand-1
|
||
|
operand-2)
|
||
|
|
||
|
(defstruct (annotated-binop (:type list)
|
||
|
(:initial-offset 3)
|
||
|
(:include binop))
|
||
|
commutative associative identity)
|
||
|
|
||
|
(make-annotated-binop :operator '*
|
||
|
:operand-1 'x
|
||
|
:operand-2 5
|
||
|
:commutative t
|
||
|
:associative t
|
||
|
:identity 1)
|
||
|
=> (nil nil binop * x 5 nil nil nil t t 1)
|
||
|
</pre><P>
|
||
|
The first two <tt>nil</tt> elements stem from the <tt>:initial-offset</tt> of <tt>2</tt>
|
||
|
in the definition of <tt>binop</tt>. The next four elements contain the
|
||
|
structure name and three slots for <tt>binop</tt>. The next three <tt>nil</tt> elements
|
||
|
stem from the <tt>:initial-offset</tt> of <tt>3</tt> in the definition of
|
||
|
<tt>annotated-binop</tt>. The last three list elements contain the additional
|
||
|
slots for an <tt>annotated-binop</tt>.
|
||
|
|
||
|
<P>
|
||
|
<BR> <HR><A NAME=tex2html3749 HREF="node179.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3747 HREF="node175.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3743 HREF="node177.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3751 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3752 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html3750 HREF="node179.html"> The Evaluator</A>
|
||
|
<B>Up:</B> <A NAME=tex2html3748 HREF="node175.html"> Structures of Explicitly </A>
|
||
|
<B> Previous:</B> <A NAME=tex2html3744 HREF="node177.html"> Named Structures</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|