| 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>setf (ANSI and GNU Common Lisp Document)</title> |
| 7 |
|
| 8 |
<meta name="description" content="setf (ANSI and GNU Common Lisp Document)"> |
| 9 |
<meta name="keywords" content="setf (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="Data-and-Control-Flow-Dictionary.html" rel="up" title="Data and Control Flow Dictionary"> |
| 15 |
<link href="shiftf.html" rel="next" title="shiftf"> |
| 16 |
<link href="get_002dsetf_002dexpansion.html" rel="prev" title="get-setf-expansion"> |
| 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="setf"></span><div class="header"> |
| 41 |
<p> |
| 42 |
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> </p> |
| 43 |
</div> |
| 44 |
<hr> |
| 45 |
<span id="setf_002c-psetf-_005bMacro_005d"></span><h4 class="subsection">5.3.64 setf, psetf [Macro]</h4> |
| 46 |
|
| 47 |
<p><code>setf</code> <i>{!<i>pair</i>}*</i> ⇒ <i>{<i>result</i>}*</i> |
| 48 |
</p> |
| 49 |
<p><code>psetf</code> <i>{!<i>pair</i>}*</i> ⇒ <i><b>nil</b></i> |
| 50 |
</p> |
| 51 |
<p><i>pair</i> ::=place newvalue<!-- /@w --> |
| 52 |
</p> |
| 53 |
<span id="Arguments-and-Values_003a_003a-82"></span><h4 class="subsubheading">Arguments and Values::</h4> |
| 54 |
|
| 55 |
<p><i>place</i>—a <i>place</i>. |
| 56 |
</p> |
| 57 |
<p><i>newvalue</i>—a <i>form</i>. |
| 58 |
</p> |
| 59 |
<p><i>results</i>—the <i>multiple values</i>_2 |
| 60 |
returned by the storing form for the last <i>place</i>, |
| 61 |
or <b>nil</b> if there are no <i>pairs</i>. |
| 62 |
</p> |
| 63 |
<span id="Description_003a_003a-117"></span><h4 class="subsubheading">Description::</h4> |
| 64 |
|
| 65 |
<p><b>setf</b> changes the <i>value</i> of <i>place</i> to be <i>newvalue</i>. |
| 66 |
</p> |
| 67 |
<p><tt>(setf place newvalue)</tt> |
| 68 |
expands into an update form that stores the |
| 69 |
result |
| 70 |
of evaluating |
| 71 |
<i>newvalue</i> into the location referred to by <i>place</i>. |
| 72 |
Some <i>place</i> forms |
| 73 |
involve uses of accessors that take optional arguments. |
| 74 |
Whether those optional arguments are permitted by |
| 75 |
<b>setf</b>, or what their use |
| 76 |
is, is up to the |
| 77 |
<b>setf</b> expander function and is not under the control |
| 78 |
of <b>setf</b>. |
| 79 |
The documentation for any <i>function</i> |
| 80 |
that accepts <b>&optional</b>, <b>&rest</b>, |
| 81 |
or <tt>&key</tt> arguments and that |
| 82 |
claims to be usable with <b>setf</b> must specify |
| 83 |
how those arguments are treated. |
| 84 |
</p> |
| 85 |
<p>If more than one <i>pair</i> is supplied, |
| 86 |
the <i>pairs</i> are processed sequentially; that is, |
| 87 |
</p> |
| 88 |
<div class="example"> |
| 89 |
<pre class="example"> (setf place-1 newvalue-1 |
| 90 |
place-2 newvalue-2 |
| 91 |
... |
| 92 |
place-N newvalue-N) |
| 93 |
</pre></div> |
| 94 |
|
| 95 |
<p>is precisely equivalent to |
| 96 |
</p> |
| 97 |
<div class="example"> |
| 98 |
<pre class="example"> (progn (setf place-1 newvalue-1) |
| 99 |
(setf place-2 newvalue-2) |
| 100 |
... |
| 101 |
(setf place-N newvalue-N)) |
| 102 |
</pre></div> |
| 103 |
|
| 104 |
<p>For <b>psetf</b>, |
| 105 |
if more than one <i>pair</i> is supplied then the assignments of new values to places are |
| 106 |
done in parallel. More precisely, all <i>subforms</i> (in both the <i>place</i> |
| 107 |
and <i>newvalue</i> <i>forms</i>) that are to be evaluated |
| 108 |
are evaluated from left to right; after all evaluations have been performed, |
| 109 |
all of the assignments are performed in an unpredictable order. |
| 110 |
</p> |
| 111 |
<p>For detailed treatment of the expansion of <b>setf</b> and <b>psetf</b>, |
| 112 |
see <a href="Kinds-of-Places.html">Kinds of Places</a>. |
| 113 |
</p> |
| 114 |
<span id="Examples_003a_003a-90"></span><h4 class="subsubheading">Examples::</h4> |
| 115 |
|
| 116 |
<div class="example"> |
| 117 |
<pre class="example"> (setq x (cons 'a 'b) y (list 1 2 3)) ⇒ (1 2 3) |
| 118 |
(setf (car x) 'x (cadr y) (car x) (cdr x) y) ⇒ (1 X 3) |
| 119 |
x ⇒ (X 1 X 3) |
| 120 |
y ⇒ (1 X 3) |
| 121 |
(setq x (cons 'a 'b) y (list 1 2 3)) ⇒ (1 2 3) |
| 122 |
(psetf (car x) 'x (cadr y) (car x) (cdr x) y) ⇒ NIL |
| 123 |
x ⇒ (X 1 A 3) |
| 124 |
y ⇒ (1 A 3) |
| 125 |
</pre></div> |
| 126 |
|
| 127 |
<span id="Affected-By_003a_003a-7"></span><h4 class="subsubheading">Affected By::</h4> |
| 128 |
|
| 129 |
<p><b>define-setf-expander</b>, |
| 130 |
<b>defsetf</b>, |
| 131 |
<b>*macroexpand-hook*</b> |
| 132 |
</p> |
| 133 |
<span id="See-Also_003a_003a-101"></span><h4 class="subsubheading">See Also::</h4> |
| 134 |
|
| 135 |
<p><a href="define_002dsetf_002dexpander.html">define-setf-expander</a> |
| 136 |
, |
| 137 |
<a href="defsetf.html">defsetf</a> |
| 138 |
, |
| 139 |
<b>macroexpand-1</b>, |
| 140 |
<a href="rotatef.html">rotatef</a> |
| 141 |
, |
| 142 |
<a href="shiftf.html">shiftf</a> |
| 143 |
, |
| 144 |
<a href="Generalized-Reference.html">Generalized Reference</a> |
| 145 |
</p> |
| 146 |
<hr> |
| 147 |
<div class="header"> |
| 148 |
<p> |
| 149 |
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> </p> |
| 150 |
</div> |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
</body> |
| 155 |
</html> |