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

cdar, cddr


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

Syntax

(cdar expr)
(cddr expr)
expr - a list or list expression
returns - the result of the last cdr function

Description

The 'cdar' and 'cddr' 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 'cdar' does a car on the expression, followed by a 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 '((1A 1B) (2A 2B) (3A 3B)))   ; make a 2-level list

(caar mylist)   ; returns 1A
(cadr mylist)   ; returns (2A 2B)

(cdar mylist)   ; returns (1B)
(cddr mylist)   ; returns ((3A 3B))

(cdar 'a)       ; error: bad argument
(cdar nil)      ; returns NIL

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 cxxr functions in the XLISP 2.0 manual.

  Back to Top


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