83 lines
4.8 KiB
HTML
83 lines
4.8 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>28.1.2.4. Accessing Slots</TITLE>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<meta name="description" value=" Accessing Slots">
|
||
|
<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=tex2html4996 HREF="node268.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html4994 HREF="node263.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html4990 HREF="node266.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html4998 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html4999 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html4997 HREF="node268.html"> Inheritance</A>
|
||
|
<B>Up:</B> <A NAME=tex2html4995 HREF="node263.html"> Classes</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html4991 HREF="node266.html"> Slots</A>
|
||
|
<HR> <P>
|
||
|
<H3><A NAME=SECTION003212400000000000000>28.1.2.4. Accessing Slots</A></H3>
|
||
|
<P>
|
||
|
<img align=bottom alt="change_begin" src="gif/change_begin.gif"><br>
|
||
|
Slots can be accessed in two ways: by use of the primitive function
|
||
|
<tt>slot-value</tt> and by use of generic functions generated by the
|
||
|
<tt>defclass</tt> form.
|
||
|
<P>
|
||
|
The function <tt>slot-value</tt> can be used with any slot name
|
||
|
specified in the <tt>defclass</tt> form to access a specific slot
|
||
|
accessible in an instance of the given class.
|
||
|
<P>
|
||
|
The macro <tt>defclass</tt> provides syntax for generating methods to
|
||
|
read and write slots. If a <i>reader</i> is requested, a method is
|
||
|
automatically generated for reading the value of the slot, but no
|
||
|
method for storing a value into it is generated. If a <i>writer</i>
|
||
|
is requested, a method is automatically generated for storing a value
|
||
|
into the slot, but no method for reading its value is generated. If
|
||
|
an <i>accessor</i> is requested, a method for reading the value of
|
||
|
the slot and a method for storing a value into the slot are
|
||
|
automatically generated. Reader and writer methods are implemented
|
||
|
using <tt>slot-value</tt>.
|
||
|
<P>
|
||
|
When a reader or writer is specified for a slot, the name of the
|
||
|
generic function to which the generated method belongs is directly
|
||
|
specified. If the name specified for the writer option is the symbol
|
||
|
<i>name</i>, the name of the generic function for writing the slot
|
||
|
is the symbol <i>name</i>, and the generic function takes two
|
||
|
arguments: the new value and the instance, in that order. If the name
|
||
|
specified for the accessor option is the symbol <i>name</i>, the
|
||
|
name of the generic function for reading the slot is the symbol <i>name</i>, and the name of the generic function for writing the slot is
|
||
|
the list <tt>(setf <i>name</i>)</tt>.
|
||
|
<P>
|
||
|
A generic function created or modified by supplying reader, writer, or
|
||
|
accessor slot options can be treated exactly as an ordinary generic
|
||
|
function.
|
||
|
<P>
|
||
|
Note that <tt>slot-value</tt> can be used to read or write the value of a
|
||
|
slot whether or not reader or writer methods exist for that slot.
|
||
|
When <tt>slot-value</tt> is used, no reader or writer methods are
|
||
|
invoked.
|
||
|
<P>
|
||
|
The macro <tt>with-slots</tt> can be used to establish a lexical
|
||
|
environment in which specified slots are lexically available as if they
|
||
|
were variables. The macro <tt>with-slots</tt> invokes the function
|
||
|
<tt>slot-value</tt> to access the specified slots.
|
||
|
<P>
|
||
|
The macro <tt>with-accessors</tt> can be used to establish a lexical
|
||
|
environment in which specified slots are lexically available through
|
||
|
their accessors as if they were variables. The macro
|
||
|
<tt>with-accessors</tt> invokes the appropriate accessors to access the
|
||
|
specified slots. Any accessors specified by <tt>with-accessors</tt> must
|
||
|
already have been defined before they are used.
|
||
|
<P>
|
||
|
<br><img align=bottom alt="change_end" src="gif/change_end.gif">
|
||
|
<P>
|
||
|
<BR> <HR><A NAME=tex2html4996 HREF="node268.html"><IMG ALIGN=BOTTOM ALT="next" SRC="icons/next_motif.gif"></A> <A NAME=tex2html4994 HREF="node263.html"><IMG ALIGN=BOTTOM ALT="up" SRC="icons/up_motif.gif"></A> <A NAME=tex2html4990 HREF="node266.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="icons/previous_motif.gif"></A> <A NAME=tex2html4998 HREF="node1.html"><IMG ALIGN=BOTTOM ALT="contents" SRC="icons/contents_motif.gif"></A> <A NAME=tex2html4999 HREF="index.html"><IMG ALIGN=BOTTOM ALT="index" SRC="icons/index_motif.gif"></A> <BR>
|
||
|
<B> Next:</B> <A NAME=tex2html4997 HREF="node268.html"> Inheritance</A>
|
||
|
<B>Up:</B> <A NAME=tex2html4995 HREF="node263.html"> Classes</A>
|
||
|
<B> Previous:</B> <A NAME=tex2html4991 HREF="node266.html"> Slots</A>
|
||
|
<HR> <P>
|
||
|
<HR>
|
||
|
<P><ADDRESS>
|
||
|
AI.Repository@cs.cmu.edu
|
||
|
</ADDRESS>
|
||
|
</BODY>
|