Contents Next: Setf Up: LISt Processing Previous: Changing Variable Values

# More Functions and Predicates

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.

```> (length '(1 2 3))
3
> (length a)
5
> (length (append a a))
10
> (length '(append a a))
3
> (length (list a a))
2
```

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.

```> (atom 'a)
T
> (atom a)
NIL
> (listp 'a)
NIL
> (listp a)
T
```
Find out for yourself how atom and listp work with the empty list, NIL.

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.

Use the appendix entries, together with the Lisp interpreter, to figure out how these functions and predicates work:

second, third, fourth,..., last, nthcdr, butlast, nbutlast, reverse, caar, cddr, cadr, cdar, constantp, integerp.

© Colin Allen & Maneesh Dhagat
March 2007