Debian Codegraph @

info/gcl/slot_002dvalue.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>slot-value (ANSI and GNU Common Lisp Document)</title>
7
8 <meta name="description" content="slot-value (ANSI and GNU Common Lisp Document)">
9 <meta name="keywords" content="slot-value (ANSI and GNU Common Lisp Document)">
10 <meta name="resource-type" content="document">
11 <meta name="distribution" content="global">
12 <meta name="Generator" content="makeinfo">
13 <link href="index.html" rel="start" title="Top">
14 <link href="Objects-Dictionary.html" rel="up" title="Objects Dictionary">
15 <link href="method_002dqualifiers.html" rel="next" title="method-qualifiers">
16 <link href="slot_002dunbound.html" rel="prev" title="slot-unbound">
17 <style type="text/css">
18 <!--
19 a.summary-letter {text-decoration: none}
20 blockquote.indentedblock {margin-right: 0em}
21 div.display {margin-left: 3.2em}
22 div.example {margin-left: 3.2em}
23 div.lisp {margin-left: 3.2em}
24 kbd {font-style: oblique}
25 pre.display {font-family: inherit}
26 pre.format {font-family: inherit}
27 pre.menu-comment {font-family: serif}
28 pre.menu-preformatted {font-family: serif}
29 span.nolinebreak {white-space: nowrap}
30 span.roman {font-family: initial; font-weight: normal}
31 span.sansserif {font-family: sans-serif; font-weight: normal}
32 ul.no-bullet {list-style: none}
33 -->
34 </style>
35
36
37 </head>
38
39 <body lang="en">
40 <span id="slot_002dvalue"></span><div class="header">
41 <p>
42 Next: <a href="method_002dqualifiers.html" accesskey="n" rel="next">method-qualifiers</a>, Previous: <a href="slot_002dunbound.html" accesskey="p" rel="prev">slot-unbound</a>, Up: <a href="Objects-Dictionary.html" accesskey="u" rel="up">Objects Dictionary</a> &nbsp; </p>
43 </div>
44 <hr>
45 <span id="slot_002dvalue-_005bFunction_005d"></span><h4 class="subsection">7.7.14 slot-value [Function]</h4>
46
47 <p><code>slot-value</code> <i>object slot-name</i> &rArr; <i>value</i>
48 </p>
49 <span id="Arguments-and-Values_003a_003a-102"></span><h4 class="subsubheading">Arguments and Values::</h4>
50
51 <p><i>object</i>&mdash;an <i>object</i>.
52 </p>
53 <p><i>name</i>&mdash;a <i>symbol</i>.
54 </p>
55 <p><i>value</i>&mdash;an <i>object</i>.
56 </p>
57 <span id="Description_003a_003a-141"></span><h4 class="subsubheading">Description::</h4>
58
59 <p>The <i>function</i> <b>slot-value</b> returns the <i>value</i> of the <i>slot</i>
60 named <i>slot-name</i> in the <i>object</i>.
61 If there is no <i>slot</i> named <i>slot-name</i>, <b>slot-missing</b> is called.
62 If the <i>slot</i> is unbound, <b>slot-unbound</b> is called.
63 </p>
64 <p>The macro <b>setf</b> can be used with <b>slot-value</b>
65 to change the value of a <i>slot</i>.
66 </p>
67 <span id="Examples_003a_003a-102"></span><h4 class="subsubheading">Examples::</h4>
68
69 <div class="example">
70 <pre class="example"> (defclass foo ()
71 ((a :accessor foo-a :initarg :a :initform 1)
72 (b :accessor foo-b :initarg :b)
73 (c :accessor foo-c :initform 3)))
74 &rArr; #&lt;STANDARD-CLASS FOO 244020371&gt;
75 (setq foo1 (make-instance 'foo :a 'one :b 'two))
76 &rArr; #&lt;FOO 36325624&gt;
77 (slot-value foo1 'a) &rArr; ONE
78 (slot-value foo1 'b) &rArr; TWO
79 (slot-value foo1 'c) &rArr; 3
80 (setf (slot-value foo1 'a) 'uno) &rArr; UNO
81 (slot-value foo1 'a) &rArr; UNO
82 (defmethod foo-method ((x foo))
83 (slot-value x 'a))
84 &rArr; #&lt;STANDARD-METHOD FOO-METHOD (FOO) 42720573&gt;
85 (foo-method foo1) &rArr; UNO
86 </pre></div>
87
88 <span id="Exceptional-Situations_003a_003a-30"></span><h4 class="subsubheading">Exceptional Situations::</h4>
89
90 <p>If an attempt is made to read a <i>slot</i> and no <i>slot</i> of
91 the name <i>slot-name</i> exists in the <i>object</i>,
92 <b>slot-missing</b> is called as follows:
93 </p>
94 <div class="example">
95 <pre class="example"> (slot-missing (class-of <i>instance</i>)
96 <i>instance</i>
97 <i>slot-name</i>
98 'slot-value)
99 </pre></div>
100
101 <p>(If <b>slot-missing</b> is invoked, its <i>primary value</i>
102 is returned by <b>slot-value</b>.)
103 </p>
104 <p>If an attempt is made to write a <i>slot</i> and no <i>slot</i> of
105 the name <i>slot-name</i> exists in the <i>object</i>,
106 <b>slot-missing</b> is called as follows:
107 </p>
108 <div class="example">
109 <pre class="example"> (slot-missing (class-of <i>instance</i>)
110 <i>instance</i>
111 <i>slot-name</i>
112 'setf
113 <i>new-value</i>)
114 </pre></div>
115
116 <p>(If <b>slot-missing</b> returns in this case, any <i>values</i> are ignored.)
117 </p>
118 <p>The specific behavior depends on <i>object</i>&rsquo;s <i>metaclass</i>.
119 An error is never signaled if <i>object</i> has <i>metaclass</i> <b>standard-class</b>.
120 An error is always signaled if <i>object</i> has <i>metaclass</i> <b>built-in-class</b>.
121 The consequences are
122 unspecified
123 if <i>object</i> has any other <i>metaclass</i>&ndash;an error
124 might or might not be signaled in this situation. Note in particular that the behavior
125 for <i>conditions</i> and <i>structures</i> is not specified.
126 </p>
127 <span id="See-Also_003a_003a-123"></span><h4 class="subsubheading">See Also::</h4>
128
129 <p><a href="slot_002dmissing.html">slot-missing</a>
130 ,
131 <a href="slot_002dunbound.html">slot-unbound</a>
132 ,
133 <a href="with_002dslots.html">with-slots</a>
134 </p>
135 <span id="Notes_003a_003a-85"></span><h4 class="subsubheading">Notes::</h4>
136
137 <p>Although no <i>implementation</i> is required to do so,
138 implementors are strongly encouraged to implement the <i>function</i> <b>slot-value</b> using
139 the <i>function</i> <tt>slot-value-using-class</tt> described in the <i>Metaobject Protocol</i>.
140 </p>
141 <p>Implementations may optimize <b>slot-value</b> by compiling it inline.
142 </p>
143 <hr>
144 <div class="header">
145 <p>
146 Next: <a href="method_002dqualifiers.html" accesskey="n" rel="next">method-qualifiers</a>, Previous: <a href="slot_002dunbound.html" accesskey="p" rel="prev">slot-unbound</a>, Up: <a href="Objects-Dictionary.html" accesskey="u" rel="up">Objects Dictionary</a> &nbsp; </p>
147 </div>
148
149
150
151 </body>
152 </html>