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
|
<h3 class="section">Predicates on Lists</h3> <p>The following predicates test whether a Lisp object is an atom, whether it is a cons cell or is a list, or whether it is the distinguished object <code>nil</code>. (Many of these predicates can be defined in terms of the others, but they are used so often that it is worth having them.) </p> <dl> <dt id="consp">Function: <strong>consp</strong> <em>object</em>
</dt> <dd><p>This function returns <code>t</code> if <var>object</var> is a cons cell, <code>nil</code> otherwise. <code>nil</code> is not a cons cell, although it <em>is</em> a list. </p></dd>
</dl> <dl> <dt id="atom">Function: <strong>atom</strong> <em>object</em>
</dt> <dd>
<p>This function returns <code>t</code> if <var>object</var> is an atom, <code>nil</code> otherwise. All objects except cons cells are atoms. The symbol <code>nil</code> is an atom and is also a list; it is the only Lisp object that is both. </p> <div class="example"> <pre class="example">(atom <var>object</var>) ≡ (not (consp <var>object</var>))
</pre>
</div> </dd>
</dl> <dl> <dt id="listp">Function: <strong>listp</strong> <em>object</em>
</dt> <dd>
<p>This function returns <code>t</code> if <var>object</var> is a cons cell or <code>nil</code>. Otherwise, it returns <code>nil</code>. </p> <div class="example"> <pre class="example">(listp '(1))
⇒ t
</pre>
<pre class="example">(listp '())
⇒ t
</pre>
</div> </dd>
</dl> <dl> <dt id="nlistp">Function: <strong>nlistp</strong> <em>object</em>
</dt> <dd>
<p>This function is the opposite of <code>listp</code>: it returns <code>t</code> if <var>object</var> is not a list. Otherwise, it returns <code>nil</code>. </p> <div class="example"> <pre class="example">(listp <var>object</var>) ≡ (not (nlistp <var>object</var>))
</pre>
</div> </dd>
</dl> <dl> <dt id="null">Function: <strong>null</strong> <em>object</em>
</dt> <dd>
<p>This function returns <code>t</code> if <var>object</var> is <code>nil</code>, and returns <code>nil</code> otherwise. This function is identical to <code>not</code>, but as a matter of clarity we use <code>null</code> when <var>object</var> is considered a list and <code>not</code> when it is considered a truth value (see <code>not</code> in <a href="combining-conditions">Combining Conditions</a>). </p> <div class="example"> <pre class="example">(null '(1))
⇒ nil
</pre>
<pre class="example">(null '())
⇒ t
</pre>
</div> </dd>
</dl> <dl> <dt id="proper-list-p">Function: <strong>proper-list-p</strong> <em>object</em>
</dt> <dd>
<p>This function returns the length of <var>object</var> if it is a proper list, <code>nil</code> otherwise (see <a href="cons-cells">Cons Cells</a>). In addition to satisfying <code>listp</code>, a proper list is neither circular nor dotted. </p> <div class="example"> <pre class="example">(proper-list-p '(a b c))
⇒ 3
</pre>
<pre class="example">(proper-list-p '(a b . c))
⇒ nil
</pre>
</div> </dd>
</dl><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/List_002drelated-Predicates.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/List_002drelated-Predicates.html</a>
</p>
</div>
|