caaar caadr cadar caddr
type: function (subr) location: built-in source file: xllist.c Common LISP compatible: yes supported on: all machines
(caaar <expr> ) (caadr <expr> ) (cadar <expr> ) (caddr <expr> ) <expr> - a list or list expression
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".
(setq mylist '( ( (a b) (c d) (e f) ) ; make a 3-level list ( (g h) (i j) (k l) ) ( (m n) (o p) (q r) ) ( (s t) (u v) (w x) ) ) ) (caaar mylist) ; returns A (caadr mylist) ; returns (G H) (cadar mylist) ; returns (C D) (caddr mylist) ; returns ((M N) (O P) (Q R)) (cdaar mylist) ; returns (B) (cdadr mylist) ; returns ((I J) (K L)) (cddar mylist) ; returns ((E F)) (cdddr mylist) ; returns (((S T) (U V) (W X)))