Debian Codegraph @

info/gcl/get.html

raw ◀ ▶
1 Debian patch touch this file
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>get (ANSI and GNU Common Lisp Document)</title>
7
8 <meta name="description" content="get (ANSI and GNU Common Lisp Document)">
9 <meta name="keywords" content="get (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="Symbols-Dictionary.html" rel="up" title="Symbols Dictionary">
15 <link href="remprop.html" rel="next" title="remprop">
16 <link href="symbol_002dvalue.html" rel="prev" title="symbol-value">
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="get"></span><div class="header">
41 <p>
42 Next: <a href="remprop.html" accesskey="n" rel="next">remprop</a>, Previous: <a href="symbol_002dvalue.html" accesskey="p" rel="prev">symbol-value</a>, Up: <a href="Symbols-Dictionary.html" accesskey="u" rel="up">Symbols Dictionary</a> &nbsp; </p>
43 </div>
44 <hr>
45 <span id="get-_005bAccessor_005d"></span><h4 class="subsection">10.2.15 get [Accessor]</h4>
46
47 <p><code>get</code> <i>symbol indicator <span class="roman">&amp;optional</span> default</i> &rArr; <i>value</i>
48 </p>
49 <p>(setf (<code> get</code> <i>symbol indicator <span class="roman">&amp;optional</span> default</i>) new-value)<br>
50 </p>
51 <span id="Arguments-and-Values_003a_003a-169"></span><h4 class="subsubheading">Arguments and Values::</h4>
52
53 <p><i>symbol</i>&mdash;a <i>symbol</i>.
54 </p>
55 <p><i>indicator</i>&mdash;an <i>object</i>.
56 </p>
57 <p><i>default</i>&mdash;an <i>object</i>.
58 The default is <b>nil</b>.
59 </p>
60 <p><i>value</i>&mdash;if the indicated property exists,
61 the <i>object</i> that is its <i>value</i>;
62 otherwise, the specified <i>default</i>.
63 </p>
64 <p><i>new-value</i>&mdash;an <i>object</i>.
65 </p>
66 <span id="Description_003a_003a-231"></span><h4 class="subsubheading">Description::</h4>
67
68 <p><b>get</b> finds a <i>property</i>
69 on the <i>property list</i>_2 of <i>symbol</i>
70 whose <i>property indicator</i> is <i>identical</i> to <i>indicator</i>,
71 and returns its corresponding <i>property value</i>.
72 </p>
73 <p>If there are multiple <i>properties</i>_1 with that <i>property indicator</i>,
74 <b>get</b> uses the first such <i>property</i>.
75 </p>
76 <p>If there is no <i>property</i> with that <i>property indicator</i>,
77 <i>default</i> is returned.
78 </p>
79 <p><b>setf</b> of <b>get</b> may be used to associate a new <i>object</i>
80 with an existing indicator already on the <i>symbol</i>&rsquo;s <i>property list</i>,
•81 or to create a new association if none exists.
82 </p>
83 <p>If there are multiple <i>properties</i>_1 with that <i>property indicator</i>,
84 <b>setf</b> of <b>get</b> associates the <i>new-value</i>
85 with the first such <i>property</i>.
86 </p>
87 <p>When a <b>get</b> <i>form</i> is used as a <b>setf</b> <i>place</i>,
88 any <i>default</i> which is supplied is evaluated according to normal
89 left-to-right evaluation rules, but its <i>value</i> is ignored.
90 </p>
91 <span id="Examples_003a_003a-152"></span><h4 class="subsubheading">Examples::</h4>
92
93 <div class="example">
94 <pre class="example"> (defun make-person (first-name last-name)
95 (let ((person (gensym &quot;PERSON&quot;)))
96 (setf (get person 'first-name) first-name)
97 (setf (get person 'last-name) last-name)
98 person)) &rArr; MAKE-PERSON
99 (defvar *john* (make-person &quot;John&quot; &quot;Dow&quot;)) &rArr; *JOHN*
100 *john* &rArr; #:PERSON4603
101 (defvar *sally* (make-person &quot;Sally&quot; &quot;Jones&quot;)) &rArr; *SALLY*
102 (get *john* 'first-name) &rArr; &quot;John&quot;
103 (get *sally* 'last-name) &rArr; &quot;Jones&quot;
104 (defun marry (man woman married-name)
105 (setf (get man 'wife) woman)
106 (setf (get woman 'husband) man)
107 (setf (get man 'last-name) married-name)
108 (setf (get woman 'last-name) married-name)
109 married-name) &rArr; MARRY
110 (marry *john* *sally* &quot;Dow-Jones&quot;) &rArr; &quot;Dow-Jones&quot;
111 (get *john* 'last-name) &rArr; &quot;Dow-Jones&quot;
112 (get (get *john* 'wife) 'first-name) &rArr; &quot;Sally&quot;
113 (symbol-plist *john*)
114 &rArr; (WIFE #:PERSON4604 LAST-NAME &quot;Dow-Jones&quot; FIRST-NAME &quot;John&quot;)
115 (defmacro age (person &amp;optional (default ''thirty-something))
116 `(get ,person 'age ,default)) &rArr; AGE
117 (age *john*) &rArr; THIRTY-SOMETHING
118 (age *john* 20) &rArr; 20
119 (setf (age *john*) 25) &rArr; 25
120 (age *john*) &rArr; 25
121 (age *john* 20) &rArr; 25
122 </pre></div>
123
124 <span id="Exceptional-Situations_003a_003a-59"></span><h4 class="subsubheading">Exceptional Situations::</h4>
125
126 <p>Should signal an error of <i>type</i> <b>type-error</b>
127 if <i>symbol</i> is not a <i>symbol</i>.
128 </p>
129 <span id="See-Also_003a_003a-204"></span><h4 class="subsubheading">See Also::</h4>
130
131 <p><a href="getf.html">getf</a>
132 ,
133 <a href="symbol_002dplist.html">symbol-plist</a>
134 ,
135 <a href="remprop.html">remprop</a>
136 </p>
137 <span id="Notes_003a_003a-124"></span><h4 class="subsubheading">Notes::</h4>
138
139 <div class="example">
140 <pre class="example"> (get x y) &equiv; (getf (symbol-plist x) y)
141 </pre></div>
142
143 <p><i>Numbers</i> and <i>characters</i> are not recommended for use
144 as <i>indicators</i> in portable code since <b>get</b> tests
145 with <b>eq</b> rather than <b>eql</b>, and consequently
146 the effect of using such <i>indicators</i> is
147 <i>implementation-dependent</i>.
148 </p>
149 <p>There is no way using <b>get</b> to distinguish an absent property from
150 one whose value is <i>default</i>. However, see <b>get-properties</b>.
151 </p>
152 <hr>
153 <div class="header">
154 <p>
155 Next: <a href="remprop.html" accesskey="n" rel="next">remprop</a>, Previous: <a href="symbol_002dvalue.html" accesskey="p" rel="prev">symbol-value</a>, Up: <a href="Symbols-Dictionary.html" accesskey="u" rel="up">Symbols Dictionary</a> &nbsp; </p>
156 </div>
157
158
159
160 </body>
161 </html>