type: function (subr) location: built-in source file: xllist.c Common LISP compatible: yes supported on: all machines
(caar <expr> ) (cadr <expr> ) <expr> - a list or list expression
The CAAR and CADR 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 CADR does a CDR on the expression, 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".
(setq mylist '( (a1 a2) ; make a 2-level list (b1 b2) (c1 c2) (d1 d2) ) ) (caar mylist) ; returns A1 (cadr mylist) ; returns (B1 B2) (cdar mylist) ; returns (A2) (cddr mylist) ; returns ((C1 C2) (D1 D2)) (caar 'a) ; error: bad argument (caar nil) ; returns NIL (cadr nil) ; returns NIL (cdar nil) ; returns NIL (cddr nil) ; returns NIL