1
0
Fork 0
cl-sites/www.cs.cmu.edu/Groups/AI/html/cltl/clm/node172.html

73 lines
3.9 KiB
HTML
Raw Normal View History

2023-10-25 11:23:21 +02:00
<!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.4. Defstruct Slot-Options</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" Defstruct Slot-Options">
<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=tex2html3678 HREF="node173.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3676 HREF="node168.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3670 HREF="node171.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3680 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3681 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3679 HREF="node173.html"> Defstruct Options</A>
<B>Up:</B> <A NAME=tex2html3677 HREF="node168.html"> Structures</A>
<B> Previous:</B> <A NAME=tex2html3671 HREF="node171.html"> Using the Automatically </A>
<HR> <P>
<H1><A NAME=SECTION002340000000000000000>19.4. Defstruct Slot-Options</A></H1>
<P>
<A NAME=DefstructSlotOptions>Each</A>
<i>slot-description</i> in a <tt>defstruct</tt> form may specify one or more
slot-options. A slot-option consists of a pair of a keyword and
a value (which is not a form to be evaluated, but the value itself).
For example:
<P><pre>
(defstruct ship
(x-position 0.0 <tt>:type</tt> short-float)
(y-position 0.0 <tt>:type</tt> short-float)
(x-velocity 0.0 <tt>:type</tt> short-float)
(y-velocity 0.0 <tt>:type</tt> short-float)
(mass *default-ship-mass* <tt>:type</tt> short-float <tt>:read-only</tt> t))
</pre><P>
This specifies that each slot will always contain a
short-format floating-point number,
and that the last slot may not be altered once a ship is constructed.
<P>
The available slot-options are as follows.
<DL COMPACT><DT><tt>:type</tt>
<DD>
The option <tt><tt>:type</tt> <i>type</i></tt> specifies that the contents of the
slot will always be of the specified data type. This is entirely
analogous to the declaration of a variable or function; indeed, it
effectively declares the result type of the access function. An
implementation may or may not choose to check the type of the new object
when initializing or assigning to a slot.
Note that the argument form <i>type</i> is not evaluated;
it must be a valid type specifier.
<P>
<DT><tt>:read-only</tt>
<DD>
The option <tt><tt>:read-only</tt> <i>x</i></tt>, where <i>x</i> is not <tt>nil</tt>,
specifies that this slot may not be
altered; it will always contain the value specified at construction time.
<tt>setf</tt> will not accept the access function for this slot.
If <i>x</i> is <tt>nil</tt>, this slot-option has no effect.
Note that the argument form <i>x</i> is not evaluated.
<P>
</DL>
<P>
Note that it is impossible to specify a slot-option unless
a default value is specified first.
<P>
<BR> <HR><A NAME=tex2html3678 HREF="node173.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html3676 HREF="node168.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html3670 HREF="node171.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html3680 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html3681 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
<B> Next:</B> <A NAME=tex2html3679 HREF="node173.html"> Defstruct Options</A>
<B>Up:</B> <A NAME=tex2html3677 HREF="node168.html"> Structures</A>
<B> Previous:</B> <A NAME=tex2html3671 HREF="node171.html"> Using the Automatically </A>
<HR> <P>
<HR>
<P><ADDRESS>
AI.Repository@cs.cmu.edu
</ADDRESS>
</BODY>