blob: b2eae408c11be8f4bc486063bbc90405d5cbb866 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<h3 class="section">Modifying Existing List Structure</h3> <p>You can modify the <small>CAR</small> and <small>CDR</small> contents of a cons cell with the primitives <code>setcar</code> and <code>setcdr</code>. These are destructive operations because they change existing list structure. Destructive operations should be applied only to mutable lists, that is, lists constructed via <code>cons</code>, <code>list</code> or similar operations. Lists created by quoting are part of the program and should not be changed by destructive operations. See <a href="mutability">Mutability</a>. </p> <blockquote> <p><b>Common Lisp note:</b> Common Lisp uses functions <code>rplaca</code> and <code>rplacd</code> to alter list structure; they change structure the same way as <code>setcar</code> and <code>setcdr</code>, but the Common Lisp functions return the cons cell while <code>setcar</code> and <code>setcdr</code> return the new <small>CAR</small> or <small>CDR</small>. </p>
</blockquote> <table class="menu" border="0" cellspacing="0"> <tr>
<td align="left" valign="top">• <a href="setcar" accesskey="1">Setcar</a>
</td>
<td> </td>
<td align="left" valign="top">Replacing an element in a list. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="setcdr" accesskey="2">Setcdr</a>
</td>
<td> </td>
<td align="left" valign="top">Replacing part of the list backbone. This can be used to remove or add elements. </td>
</tr> <tr>
<td align="left" valign="top">• <a href="rearrangement" accesskey="3">Rearrangement</a>
</td>
<td> </td>
<td align="left" valign="top">Reordering the elements in a list; combining lists. </td>
</tr> </table><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Modifying-Lists.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Modifying-Lists.html</a>
</p>
</div>
|