1
0
Fork 0
cl-sites/HyperSpec-7-0/HyperSpec/Body/f_slt_va.htm
2024-04-01 10:24:07 +02:00

93 lines
7.6 KiB
HTML

<!-- Common Lisp HyperSpec (TM), version 7.0 generated by Kent M. Pitman on Mon, 11-Apr-2005 2:31am EDT -->
<HTML>
<HEAD>
<TITLE>CLHS: Function SLOT-VALUE</TITLE>
<LINK HREF="../Data/clhs.css" REL="stylesheet" TYPE="text/css" />
<META HTTP-EQUIV="Author" CONTENT="Kent M. Pitman">
<META HTTP-EQUIV="Organization" CONTENT="LispWorks Ltd.">
<LINK REL=TOP HREF="../Front/index.htm">
<LINK REL=COPYRIGHT HREF="../Front/Help.htm#Legal">
<LINK REL=DISCLAIMER HREF="../Front/Help.htm#Disclaimer">
<LINK REL=PREV HREF="f_slt_un.htm">
<LINK REL=UP HREF="c_object.htm">
<LINK REL=NEXT HREF="f_method.htm">
</HEAD>
<BODY>
<H1><A REV=MADE HREF="http://www.lispworks.com/"><IMG WIDTH=80 HEIGHT=65 ALT="[LISPWORKS]" SRC="../Graphics/LWSmall.gif" ALIGN=Bottom></A><A REL=TOP HREF="../Front/index.htm"><IMG WIDTH=237 HEIGHT=65 ALT="[Common Lisp HyperSpec (TM)]" SRC="../Graphics/CLHS_Sm.gif" ALIGN=Bottom></A> <A REL=PREV HREF="f_slt_un.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Previous]" SRC="../Graphics/Prev.gif" ALIGN=Bottom></A><A REL=UP HREF="c_object.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Up]" SRC="../Graphics/Up.gif" ALIGN=Bottom></A><A REL=NEXT HREF="f_method.htm"><IMG WIDTH=40 HEIGHT=40 ALT="[Next]" SRC="../Graphics/Next.gif" ALIGN=Bottom></A></H1>
<HR>
<A NAME="slot-value"><I>Function</I> <B>SLOT-VALUE</B></A> <P>
<P><B>Syntax:</B><P>
<P>
<B>slot-value</B> <I>object slot-name</I> =&gt; <I>value</I><P>
<P>
<P><B>Arguments and Values:</B><P>
<P>
<I>object</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
<I>name</I>---a <A REL=DEFINITION HREF="26_glo_s.htm#symbol"><I>symbol</I></A>. <P>
<I>value</I>---an <A REL=DEFINITION HREF="26_glo_o.htm#object"><I>object</I></A>. <P>
<P><B>Description:</B><P>
<P>
The <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#slot-value"><B>slot-value</B></A> returns the <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>value</I></A> of the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> named <I>slot-name</I> in the <I>object</I>. If there is no <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> named <I>slot-name</I>, <A REL=DEFINITION HREF="f_slt_mi.htm#slot-missing"><B>slot-missing</B></A> is called. If the <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> is unbound, <A REL=DEFINITION HREF="f_slt_un.htm#slot-unbound"><B>slot-unbound</B></A> is called. <P>
The macro <A REL=DEFINITION HREF="m_setf_.htm#setf"><B>setf</B></A> can be used with <A REL=DEFINITION HREF="#slot-value"><B>slot-value</B></A> to change the value of a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A>. <P>
<P><B>Examples:</B><P>
<P>
<PRE>
(defclass foo ()
((a :accessor foo-a :initarg :a :initform 1)
(b :accessor foo-b :initarg :b)
(c :accessor foo-c :initform 3)))
=&gt; #&lt;STANDARD-CLASS FOO 244020371&gt;
(setq foo1 (make-instance 'foo :a 'one :b 'two))
=&gt; #&lt;FOO 36325624&gt;
(slot-value foo1 'a) =&gt; ONE
(slot-value foo1 'b) =&gt; TWO
(slot-value foo1 'c) =&gt; 3
(setf (slot-value foo1 'a) 'uno) =&gt; UNO
(slot-value foo1 'a) =&gt; UNO
(defmethod foo-method ((x foo))
(slot-value x 'a))
=&gt; #&lt;STANDARD-METHOD FOO-METHOD (FOO) 42720573&gt;
(foo-method foo1) =&gt; UNO
</PRE>
</TT> <P>
<P><B>Affected By:</B> None.
<P>
<P><B>Exceptional Situations:</B><P>
<P>
If an attempt is made to read a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> and no <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> of the name <I>slot-name</I> exists in the <I>object</I>, <A REL=DEFINITION HREF="f_slt_mi.htm#slot-missing"><B>slot-missing</B></A> is called as follows: <P>
<PRE>
(slot-missing (class-of instance)
instance
slot-name
'slot-value)
</PRE>
</TT> <P>
(If <A REL=DEFINITION HREF="f_slt_mi.htm#slot-missing"><B>slot-missing</B></A> is invoked, its <A REL=DEFINITION HREF="26_glo_p.htm#primary_value"><I>primary value</I></A> is returned by <A REL=DEFINITION HREF="#slot-value"><B>slot-value</B></A>.) <P>
If an attempt is made to write a <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> and no <A REL=DEFINITION HREF="26_glo_s.htm#slot"><I>slot</I></A> of the name <I>slot-name</I> exists in the <I>object</I>, <A REL=DEFINITION HREF="f_slt_mi.htm#slot-missing"><B>slot-missing</B></A> is called as follows: <P>
<PRE>
(slot-missing (class-of instance)
instance
slot-name
'setf
new-value)
</PRE>
</TT> <P>
(If <A REL=DEFINITION HREF="f_slt_mi.htm#slot-missing"><B>slot-missing</B></A> returns in this case, any <A REL=DEFINITION HREF="26_glo_v.htm#value"><I>values</I></A> are ignored.) <P>
The specific behavior depends on <I>object</I>'s <A REL=DEFINITION HREF="26_glo_m.htm#metaclass"><I>metaclass</I></A>. An error is never signaled if <I>object</I> has <A REL=DEFINITION HREF="26_glo_m.htm#metaclass"><I>metaclass</I></A> <A REL=DEFINITION HREF="t_std_cl.htm#standard-class"><B>standard-class</B></A>. An error is always signaled if <I>object</I> has <A REL=DEFINITION HREF="26_glo_m.htm#metaclass"><I>metaclass</I></A> <A REL=DEFINITION HREF="t_built_.htm#built-in-class"><B>built-in-class</B></A>. The consequences are unspecified if <I>object</I> has any other <A REL=DEFINITION HREF="26_glo_m.htm#metaclass"><I>metaclass</I></A>--an error might or might not be signaled in this situation. Note in particular that the behavior for <A REL=DEFINITION HREF="26_glo_c.htm#condition"><I>conditions</I></A> and <A REL=DEFINITION HREF="26_glo_s.htm#structure"><I>structures</I></A> is not specified. <P>
<P><B>See Also:</B><P>
<P>
<A REL=DEFINITION HREF="f_slt_mi.htm#slot-missing"><B>slot-missing</B></A>, <A REL=DEFINITION HREF="f_slt_un.htm#slot-unbound"><B>slot-unbound</B></A>, <A REL=DEFINITION HREF="m_w_slts.htm#with-slots"><B>with-slots</B></A> <P>
<P><B>Notes:</B><P>
<P>
Although no <A REL=DEFINITION HREF="26_glo_i.htm#implementation"><I>implementation</I></A> is required to do so, implementors are strongly encouraged to implement the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <A REL=DEFINITION HREF="#slot-value"><B>slot-value</B></A> using the <A REL=DEFINITION HREF="26_glo_f.htm#function"><I>function</I></A> <TT>slot-value-using-class</TT> described in the <A REL=DEFINITION HREF="26_glo_m.htm#metaobject_protocol"><I>Metaobject Protocol</I></A>. <P>
Implementations may optimize <A REL=DEFINITION HREF="#slot-value"><B>slot-value</B></A> by compiling it inline. <P>
<P><HR>The following <A REL=META HREF="../Front/X3J13Iss.htm">X3J13 cleanup issues</A>, <I>not part of the specification</I>, apply to this section:<P><UL><LI> <A REL=CHILD HREF="../Issues/iss320.htm">SLOT-VALUE-METACLASSES:LESS-MINIMAL</A><LI> <A REL=CHILD HREF="../Issues/iss319.htm">SLOT-MISSING-VALUES:SPECIFY</A><P></UL><HR>
<A REL=NAVIGATOR HREF="../Front/StartPts.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Starting Points]" SRC="../Graphics/StartPts.gif" ALIGN=Bottom></A><A REL=TOC HREF="../Front/Contents.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Contents]" SRC="../Graphics/Contents.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Master.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Index]" SRC="../Graphics/Index.gif" ALIGN=Bottom></A><A REL=INDEX HREF="../Front/X_Symbol.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Symbols]" SRC="../Graphics/Symbols.gif" ALIGN=Bottom></A><A REL=GLOSSARY HREF="../Body/26_a.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Glossary]" SRC="../Graphics/Glossary.gif" ALIGN=Bottom></A><A HREF="../Front/X3J13Iss.htm"><IMG WIDTH=80 HEIGHT=40 ALT="[Issues]" SRC="../Graphics/Issues.gif" ALIGN=Bottom></A><BR>
<A REL=COPYRIGHT HREF="../Front/Help.htm#Legal"><I>Copyright 1996-2005, LispWorks Ltd. All rights reserved.</I></A><P>
</BODY>
</HTML>