Debian Codegraph @

docsrc/xlisp/xlisp-doc/reference/delete-if-not.htm

raw
1 <html><head><title>XLISP delete-if-not</title>
2
3 <link rel="stylesheet" type="text/css" href="reference.css">
4
5 </head>
6
7 <body>
8
9 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
10 <a href="../manual/contents.htm">Contents</a> |
11 <a href="../tutorials/tutorials.htm">Tutorials</a> |
12 <a href="../examples/examples.htm">Examples</a> |
13 <a href="reference-index.htm">Reference</a>
14
15 <hr>
16
17 <h1>delete-if-not</h1>
18
19 <hr>
20
21 <p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
22 <tr valign="top">
23 <td><nobr>Type:</nobr></td>
24 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
25 <td width="100%"><nobr>function (subr)</nobr></td>
26 </tr>
27 <tr valign="top">
28 <td><nobr>Source:</nobr></td>
29 <td><nobr>&nbsp;&nbsp;-&nbsp;&nbsp;</nobr></td>
30 <td width="100%"><nobr>xllist.c</nobr></td>
31 </tr>
32 </tbody></table></p>
33
34 <h2>Syntax</h2>
35
36 <dl>
37 <dt>(delete-if-not <i>test list</i>)</dt>
38 <dd><i>test</i> - the test function to be performed<br>
39 <i>list</i> - the list to delete from<br>
40 returns - the list with non-matching elements deleted</dd>
41 </dl>
42
43 <h2>Description</h2>
44
45 <p>The 'delete-if-not' function destructively modifies the 'list' by
46 removing the elements of the list that fail the 'test'. The destructive
47 aspect of this operation means that the actual symbol value is used in the
48 list-modifying operations, not a copy.</p>
49
50 <p>'list' must evaluate to a valid list. An atom for 'list' will result in
51 an error:</p>
52
53 <pre class="example">
54 <font color="#AA0000">error: bad argument type</font>
55 </pre>
56
57 <p>Having <a href="nil.htm">NIL</a> for 'list' will return a
58 <a href="nil.htm">NIL</a> as the result.</p>
59
60 <h2>Examples</h2>
61
62 <p><b>Caution:</b> there's a bug:</p>
63
64 <pre class="example">
65 (setq mylist '(1 2 3 4 5 6 7 8)) <font color="#008844">; set up a list of numbers</font>
66 (delete-if-not 'evenp mylist) <font color="#008844">; returns (2 4 6 8)</font>
67 (print mylist) <font color="#008844">; prints (1 2 4 6 8)</font> <font color="#AA0000">&lt;-BUG!</font>
68
69 (setq mylist '(1 2 3 4 5 6 7 8)) <font color="#008844">; set up the same list again</font>
70 (setq mylist (delete-if-not 'evenp mylist)) <font color="#008844">; returns (3 5 7)</font>
71 (print mylist) <font color="#008844">; prints (3 5 7)</font> <font color="#009900">&lt;-OK</font>
72
73 (setq mylist '(1 2 3 4 5 6 7 8)) <font color="#008844">; ... again ...</font>
74 (delete-if-not 'oddp mylist) <font color="#008844">; returns (1 3 5 7)</font>
75 (print mylist) <font color="#008844">; prints (1 3 5 7)</font> <font color="#009900">&lt;-OK</font>
76
77 (setq mylist '(1 2 3 4 5 6 7 8)) <font color="#008844">; ... and again ...</font>
78 (setq mylist (delete-if-not 'oddp mylist)) <font color="#008844">; returns (1 3 5 7)</font>
79 (print mylist) <font color="#008844">; prints (1 3 5 7)</font> <font color="#009900">&lt;-OK</font>
80 </pre>
81
82 <p><b>Bug:</b> 'delete-if-not' will return the proper value, but it does not
83 always properly modify the symbol containing the value. This seems to be
84 true if the first element of the 'list' fails the test [and should be
85 deleted]. It's always better to use 'delete-if-not' together with
86 <a href="setq.htm">setq</a> or
87 <a href="setf.htm">setf</a> as shown in <nobr>example 2</nobr>
88 <nobr>and 4.</nobr></p>
89
90 <p><b>Common Lisp:</b> XLISP does not support the ':from-end', ':start',
91 ':end', ':count' and ':key' keywords which Common Lisp does.</p>
92
93 <p>See the
94 <a href="../manual/xlisp-man-017.htm#delete-if-not">delete-if-not</a>
95 function in the <nobr>XLISP 2.0</nobr> manual.</p>
96
97 <p><nobr>&nbsp;&nbsp;<a href="#top">Back to Top</nobr></a></p>
98
99 <hr>
100
101 <a href="../start.htm">Nyquist / XLISP 2.0</a>&nbsp; -&nbsp;
102 <a href="../manual/contents.htm">Contents</a> |
103 <a href="../tutorials/tutorials.htm">Tutorials</a> |
104 <a href="../examples/examples.htm">Examples</a> |
105 <a href="reference-index.htm">Reference</a>
106
107 </body></html>