File: setf.html

package info (click to toggle)
gcl 2.6.14-21
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 60,864 kB
  • sloc: ansic: 177,407; lisp: 151,509; asm: 128,169; sh: 22,510; cpp: 11,923; tcl: 3,181; perl: 2,930; makefile: 2,360; sed: 334; yacc: 226; lex: 95; awk: 30; fortran: 24; csh: 23
file content (155 lines) | stat: -rw-r--r-- 5,785 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>setf (ANSI and GNU Common Lisp Document)</title>

<meta name="description" content="setf (ANSI and GNU Common Lisp Document)">
<meta name="keywords" content="setf (ANSI and GNU Common Lisp Document)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="Data-and-Control-Flow-Dictionary.html" rel="up" title="Data and Control Flow Dictionary">
<link href="shiftf.html" rel="next" title="shiftf">
<link href="get_002dsetf_002dexpansion.html" rel="prev" title="get-setf-expansion">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<span id="setf"></span><div class="header">
<p>
Next: <a href="shiftf.html" accesskey="n" rel="next">shiftf</a>, Previous: <a href="get_002dsetf_002dexpansion.html" accesskey="p" rel="prev">get-setf-expansion</a>, Up: <a href="Data-and-Control-Flow-Dictionary.html" accesskey="u" rel="up">Data and Control Flow Dictionary</a> &nbsp; </p>
</div>
<hr>
<span id="setf_002c-psetf-_005bMacro_005d"></span><h4 class="subsection">5.3.64 setf, psetf                                                         [Macro]</h4>

<p><code>setf</code>  <i>{!<i>pair</i>}*</i> &rArr;  <i>{<i>result</i>}*</i>
</p>
<p><code>psetf</code>  <i>{!<i>pair</i>}*</i> &rArr;  <i><b>nil</b></i>
</p>
<p><i>pair</i>&nbsp;::=place&nbsp;newvalue<!-- /@w -->
</p>
<span id="Arguments-and-Values_003a_003a-82"></span><h4 class="subsubheading">Arguments and Values::</h4>

<p><i>place</i>&mdash;a <i>place</i>.
</p>
<p><i>newvalue</i>&mdash;a <i>form</i>.
</p>
<p><i>results</i>&mdash;the <i>multiple values</i>_2 
                  returned by the storing form for the last <i>place</i>,
                  or <b>nil</b> if there are no <i>pairs</i>.
</p>
<span id="Description_003a_003a-117"></span><h4 class="subsubheading">Description::</h4>

<p><b>setf</b> changes the <i>value</i> of <i>place</i> to be <i>newvalue</i>.
</p>
<p><tt>(setf place newvalue)</tt> 
expands into an update form that stores the 
result 
of evaluating
<i>newvalue</i> into the location referred to by <i>place</i>.
   Some <i>place</i> forms 
involve uses of accessors that take optional arguments. 
   Whether those optional arguments are permitted by 
<b>setf</b>, or what their use
   is, is up to the 
<b>setf</b> expander function and is not under the control
   of <b>setf</b>. 
The documentation for any <i>function</i> 
that accepts <b>&amp;optional</b>, <b>&amp;rest</b>,
   or <tt>&amp;key</tt> arguments and that 
claims to be usable with <b>setf</b> must specify
   how those arguments are treated.
</p>
<p>If more than one <i>pair</i> is supplied,
the <i>pairs</i> are processed sequentially; that is,
</p>
<div class="example">
<pre class="example"> (setf place-1 newvalue-1
       place-2 newvalue-2
       ...
       place-N newvalue-N)
</pre></div>

<p>is precisely equivalent to
</p>
<div class="example">
<pre class="example"> (progn (setf place-1 newvalue-1)
        (setf place-2 newvalue-2)
        ...
        (setf place-N newvalue-N))
</pre></div>

<p>For <b>psetf</b>, 
if more than one <i>pair</i> is supplied then the assignments of new values to places are
done in parallel.  More precisely, all <i>subforms</i> (in both the <i>place</i>
and <i>newvalue</i> <i>forms</i>) that are to be evaluated
are evaluated from left to right; after all evaluations have been performed,
all of the assignments are performed in an unpredictable order.
</p>
<p>For detailed treatment of the expansion of <b>setf</b> and <b>psetf</b>,
see <a href="Kinds-of-Places.html">Kinds of Places</a>.
</p>
<span id="Examples_003a_003a-90"></span><h4 class="subsubheading">Examples::</h4>

<div class="example">
<pre class="example"> (setq x (cons 'a 'b) y (list 1 2 3)) &rArr;  (1 2 3) 
 (setf (car x) 'x (cadr y) (car x) (cdr x) y) &rArr;  (1 X 3) 
 x &rArr;  (X 1 X 3) 
 y &rArr;  (1 X 3) 
 (setq x (cons 'a 'b) y (list 1 2 3)) &rArr;  (1 2 3) 
 (psetf (car x) 'x (cadr y) (car x) (cdr x) y) &rArr;  NIL 
 x &rArr;  (X 1 A 3) 
 y &rArr;  (1 A 3) 
</pre></div>

<span id="Affected-By_003a_003a-7"></span><h4 class="subsubheading">Affected By::</h4>

<p><b>define-setf-expander</b>,
<b>defsetf</b>,
<b>*macroexpand-hook*</b>
</p>
<span id="See-Also_003a_003a-101"></span><h4 class="subsubheading">See Also::</h4>

<p><a href="define_002dsetf_002dexpander.html">define-setf-expander</a>
,
<a href="defsetf.html">defsetf</a>
,
<b>macroexpand-1</b>,
<a href="rotatef.html">rotatef</a>
,
<a href="shiftf.html">shiftf</a>
,
<a href="Generalized-Reference.html">Generalized Reference</a>
</p>
<hr>
<div class="header">
<p>
Next: <a href="shiftf.html" accesskey="n" rel="next">shiftf</a>, Previous: <a href="get_002dsetf_002dexpansion.html" accesskey="p" rel="prev">get-setf-expansion</a>, Up: <a href="Data-and-Control-Flow-Dictionary.html" accesskey="u" rel="up">Data and Control Flow Dictionary</a> &nbsp; </p>
</div>



</body>
</html>