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

cdaar ... cdddr


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

Syntax

(cdaar expr)
(cdadr expr)
(cddar expr)
(cdddr expr)
expr - a list or list expression
returns - the result of the last cdr function

Description

The 'cdaar', 'cdadr', 'cddar' and 'cdddr' 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 'cddar' does a car on the expression, followed by a cdr , followed by another cdr. 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.

  Back to Top


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