XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

 Type: - function (subr) Source: - xllist.c

## Syntax

(caaar expr)
expr - a list or list expression
returns - the result of the last car function

## Description

The 'caaar', 'caadr', 'cadar' and 'caddr' functions go through the list expression and perform a sequence of car / cdr operations. The sequence of operations is performed from right to left. So 'caddr' does a cdr on the expression, followed by a cdr , followed by a car. If at any point the list is NIL , NIL is returned. If at any point a car operation is performed on an atom [as opposed to a list] an error is reported:

```error: bad argument
```

## Examples

```(setq mylist '(((11A 11B) (12A 12B) (13A 13B))   ; make a 3-level list
((21A 21B) (22A 22B) (23A 23B))
((31A 31B) (32A 32B) (33A 33B))
((41A 41B) (42A 42B) (43A 43B))))

(caaar mylist)   ; returns 11A
(caadr mylist)   ; returns (21A 21B)
(cadar mylist)   ; returns (12A 12B)
(caddr mylist)   ; returns ((31A 31B) (32A 32B) (33A 33B))

(cdaar mylist)   ; returns (11B)
(cdadr mylist)   ; returns ((22A 22B) (23A 23B))
(cddar mylist)   ; returns ((13A 13B))
(cdddr mylist)   ; returns (((41A 41B) (42A 42B) (43A 43B)))
```

Note: The 'cx...xr' functions are part of the historical Lisp functions. In XLISP you probably will find it much more convenient to work with the modern lisp functions like nth and nthcdr. Please read the list functions page in the XLISP 2.0 manual.

See the cxxxr functions in the XLISP 2.0 manual.