cdaar cdadr cddar cdddr
type: function (subr) location: built-in source file: xllist.c Common LISP compatible: yes supported on: all machines
(cdaar <expr> ) (cdadr <expr> ) (cddar <expr> ) (cdddr <expr> ) <expr> - a list or list expression
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".
(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) ) ) ) (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))) (caaar mylist) ; returns A (caadr mylist) ; returns (G H) (cadar mylist) ; returns (C D) (caddr mylist) ; returns ((M N) (O P) (Q R))