emacs.d/clones/colinallen.dnsalias.org/lp/node12.html

74 lines
2.2 KiB
HTML
Raw Normal View History

2022-08-02 12:34:59 +02:00
<!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Originally converted to HTML using LaTeX2HTML 95 (Thu Jan 19 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE> More Functions and Predicates</TITLE>
</HEAD>
<BODY>
<meta name="description" value=" More Functions and Predicates">
<meta name="keywords" value="lp">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
<BR> <HR>
<A HREF="node13.html"><IMG ALIGN=BOTTOM ALT="next" SRC="next_motif.gif"></A>
<A HREF="node2.html"><IMG ALIGN=BOTTOM ALT="up" SRC="up_motif.gif"></A>
<A HREF="node11.html"><IMG ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif"></A> <BR>
<A HREF="lp.html"><B>Contents</B></A>
<B> Next:</B>
<A HREF="node13.html"> Setf</A>
<B>Up:</B>
<A HREF="node2.html"> LISt Processing</A>
<B> Previous:</B>
<A HREF="node11.html"> Changing Variable Values</A>
<BR> <HR> <P>
<H1> More Functions and Predicates</H1>
<P>
To find out the length of a list, there is a function called,
appropriately enough, length. It takes a single argument which
should be a list.
<BLOCKQUOTE>
<PRE>&gt; (length '(1 2 3))
3
&gt; (length a)
5
&gt; (length (append a a))
10
&gt; (length '(append a a))
3
&gt; (length (list a a))
2
</PRE>
</BLOCKQUOTE>
<P>
Predicates are functions that always return either t or nil. Atom is a predicate that determines whether its argument is an atom.
Listp returns t if its argument is a list, and nil otherwise.
<BLOCKQUOTE>
<PRE>&gt; (atom 'a)
T
&gt; (atom a)
NIL
&gt; (listp 'a)
NIL
&gt; (listp a)
T
</PRE>
</BLOCKQUOTE>
Find out for yourself how atom and listp work with the empty list,
NIL.
<P>
Symbolp and numberp are also useful predicates. Experiment with them
to find out how they work. Constantp is less frequently used, but
might come in handy some time.
<P>
Use the appendix entries, together with the Lisp interpreter, to figure out how these functions and predicates work:
<P>
second, third, fourth,..., last, nthcdr, butlast, nbutlast,
reverse, caar, cddr, cadr, cdar, constantp, integerp.
<BR> <HR>
<P>
<ADDRESS>
<I>&#169; Colin Allen &amp; Maneesh Dhagat <BR>
March 2007 </I>
</ADDRESS>
</BODY>