1
0
Fork 0
cl-sites/novaspec.org/cl/f_slot-value.html
2025-02-05 18:52:26 +01:00

465 lines
No EOL
9.2 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>slot-value | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_slot-value.html"
><LINK REL="next" HREF="f_method-qualifiers.html" TYPE="text/html" TITLE="method-qualifiers"
><LINK REL="prev" HREF="f_slot-unbound.html" TYPE="text/html" TITLE="slot-unbound"
><LINK REL="up" HREF="7_7_Objects_Dictionary.html" TYPE="text/html" TITLE="7.7 Objects Dictionary"
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
><SCRIPT SRC="dpans.js%3F3909942064"
></SCRIPT
><SCRIPT SRC="apropos.js%3F3909942064"
></SCRIPT
></HEAD
><BODY
><DIV
><DIV CLASS="topnav"
><DIV CLASS="breadcrumb"
><SPAN CLASS="breadcrumb-item"
><A HREF="index.html"
>Common Lisp Nova Spec</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="7_Objects.html"
>7. Objects</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="7_7_Objects_Dictionary.html"
>7.7 Objects Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_slot-value.html"
>slot-value</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_slot-unbound.html" CLASS="prev"
>&#8592;</A
><SPAN ID="apropos-label"
>Apropos </SPAN
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
><A HREF="f_method-qualifiers.html" CLASS="next"
>&#8594;</A
></DIV
><DIV ID="apropos-res"
></DIV
></DIV
></DIV
><DIV CLASS="matter"
><DIV CLASS="com"
><DIV CLASS="begincom"
><HR
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
><TR
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="slot-value"
></SPAN
><B
>slot-value</B
></TD
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
><I
>Function</I
></TD
></TR
></TABLE
><HR
></DIV
><UL CLASS="subtoc"
></UL
><DL
><DT
><B
>Syntax</B
></DT
><DD
><P CLASS="j"
><B
>slot-value</B
> <SPAN CLASS="cmssi"
>object</SPAN
> <SPAN CLASS="cmssi"
>slot-name</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>value</SPAN
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>object</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>name</VAR
> &#8212; a <A HREF="26_1_Glossary.html#symbol"
><EM CLASS="term"
>symbol</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>value</VAR
> &#8212; an <A HREF="26_1_Glossary.html#object"
><EM CLASS="term"
>object</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
>The <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> <A HREF="f_slot-value.html" CLASS="funref"
><B
>slot-value</B
></A
> returns the <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>value</EM
></A
> of the <A HREF="26_1_Glossary.html#slot"
><EM CLASS="term"
>slot</EM
></A
> named <VAR CLASS="param"
>slot-name</VAR
> in the <VAR CLASS="param"
>object</VAR
>. If there is no <A HREF="26_1_Glossary.html#slot"
><EM CLASS="term"
>slot</EM
></A
> named <VAR CLASS="param"
>slot-name</VAR
>, <A HREF="f_slot-missing.html" CLASS="funref"
><B
>slot-missing</B
></A
> is called. If the <A HREF="26_1_Glossary.html#slot"
><EM CLASS="term"
>slot</EM
></A
> is unbound, <A HREF="f_slot-unbound.html" CLASS="funref"
><B
>slot-unbound</B
></A
> is called. </P
><P CLASS="j"
>The macro <A HREF="f_setf.html" CLASS="macref"
><B
>setf</B
></A
> can be used with <A HREF="f_slot-value.html" CLASS="funref"
><B
>slot-value</B
></A
> to change the value of a <A HREF="26_1_Glossary.html#slot"
><EM CLASS="term"
>slot</EM
></A
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
> (defclass foo ()
((a :accessor foo-a :initarg :a :initform 1)
(b :accessor foo-b :initarg :b)
(c :accessor foo-c :initform 3)))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;STANDARD-CLASS FOO 244020371&gt;
(setq foo1 (make-instance 'foo :a 'one :b 'two))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;FOO 36325624&gt;
(slot-value foo1 'a) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> ONE
(slot-value foo1 'b) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> TWO
(slot-value foo1 'c) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 3
(setf (slot-value foo1 'a) 'uno) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> UNO
(slot-value foo1 'a) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> UNO
(defmethod foo-method ((x foo))
(slot-value x 'a))
<SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #&lt;STANDARD-METHOD FOO-METHOD (FOO) 42720573&gt;
(foo-method foo1) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> UNO</PRE
></DD
><DT
><B
>Exceptional Situations</B
></DT
><DD
><P CLASS="j"
>If an attempt is made to read a <A HREF="26_1_Glossary.html#slot"
><EM CLASS="term"
>slot</EM
></A
> and no <A HREF="26_1_Glossary.html#slot"
><EM CLASS="term"
>slot</EM
></A
> of the name <VAR CLASS="param"
>slot-name</VAR
> exists in the <VAR CLASS="param"
>object</VAR
>, <A HREF="f_slot-missing.html" CLASS="funref"
><B
>slot-missing</B
></A
> is called as follows:</P
><PRE CLASS="screen"
>(slot-missing (class-of <I CLASS="i"
><I
>instance</I
></I
>)
<I CLASS="i"
><I
>instance</I
></I
>
<I CLASS="i"
><I
>slot-name</I
></I
>
'slot-value)</PRE
><P CLASS="j"
>(If <A HREF="f_slot-missing.html" CLASS="funref"
><B
>slot-missing</B
></A
> is invoked, its <A HREF="26_1_Glossary.html#primary_value"
><EM CLASS="term"
>primary value</EM
></A
> is returned by <A HREF="f_slot-value.html" CLASS="funref"
><B
>slot-value</B
></A
>.) </P
><P CLASS="j"
>If an attempt is made to write a <A HREF="26_1_Glossary.html#slot"
><EM CLASS="term"
>slot</EM
></A
> and no <A HREF="26_1_Glossary.html#slot"
><EM CLASS="term"
>slot</EM
></A
> of the name <VAR CLASS="param"
>slot-name</VAR
> exists in the <VAR CLASS="param"
>object</VAR
>, <A HREF="f_slot-missing.html" CLASS="funref"
><B
>slot-missing</B
></A
> is called as follows:</P
><PRE CLASS="screen"
>(slot-missing (class-of <I CLASS="i"
><I
>instance</I
></I
>)
<I CLASS="i"
><I
>instance</I
></I
>
<I CLASS="i"
><I
>slot-name</I
></I
>
'setf
<I CLASS="i"
><I
>new-value</I
></I
>)</PRE
><P CLASS="j"
>(If <A HREF="f_slot-missing.html" CLASS="funref"
><B
>slot-missing</B
></A
> returns in this case, any <A HREF="26_1_Glossary.html#value"
><EM CLASS="term"
>values</EM
></A
> are ignored.) </P
><P CLASS="j"
>The specific behavior depends on <VAR CLASS="param"
>object</VAR
>&#8217;s <A HREF="26_1_Glossary.html#metaclass"
><EM CLASS="term"
>metaclass</EM
></A
>. An error is never signaled if <VAR CLASS="param"
>object</VAR
> has <A HREF="26_1_Glossary.html#metaclass"
><EM CLASS="term"
>metaclass</EM
></A
> <A HREF="t_standard-class.html" CLASS="typeref"
><B
>standard-class</B
></A
>. An error is always signaled if <VAR CLASS="param"
>object</VAR
> has <A HREF="26_1_Glossary.html#metaclass"
><EM CLASS="term"
>metaclass</EM
></A
> <A HREF="t_built-in-class.html" CLASS="typeref"
><B
>built-in-class</B
></A
>. The consequences are unspecified if <VAR CLASS="param"
>object</VAR
> has any other <A HREF="26_1_Glossary.html#metaclass"
><EM CLASS="term"
>metaclass</EM
></A
>&#8211;an error might or might not be signaled in this situation. Note in particular that the behavior for <A HREF="26_1_Glossary.html#condition"
><EM CLASS="term"
>conditions</EM
></A
> and <A HREF="26_1_Glossary.html#structure"
><EM CLASS="term"
>structures</EM
></A
> is not specified.</P
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="f_slot-missing.html" CLASS="funref"
><B
>slot-missing</B
></A
>, <A HREF="f_slot-unbound.html" CLASS="funref"
><B
>slot-unbound</B
></A
>, <A HREF="f_with-slots.html" CLASS="macref"
><B
>with-slots</B
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><P CLASS="j"
>Although no <A HREF="26_1_Glossary.html#implementation"
><EM CLASS="term"
>implementation</EM
></A
> is required to do so, implementors are strongly encouraged to implement the <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> <A HREF="f_slot-value.html" CLASS="funref"
><B
>slot-value</B
></A
> using the <A HREF="26_1_Glossary.html#function"
><EM CLASS="term"
>function</EM
></A
> <CODE CLASS="f"
>slot-value-using-class</CODE
> described in the <A HREF="26_1_Glossary.html#Metaobject_Protocol"
><EM CLASS="term"
>Metaobject Protocol</EM
></A
>. </P
><P CLASS="j"
>Implementations may optimize <A HREF="f_slot-value.html" CLASS="funref"
><B
>slot-value</B
></A
> by compiling it inline.</P
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_slot-unbound.html" CLASS="prev"
>&#8592;</A
><A HREF="f_method-qualifiers.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>