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

cdaaar ... cddddr


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

Syntax

(cdaaar expr)
(cdaadr expr)
(cdadar expr)
(cdaddr expr)
(cddaar expr)
(cddadr expr)
(cdddar expr)
(cddddr expr)
expr - a list or list expression
returns - the result of the last cdr function

Description

The 'cdaaar' ... 'cddddr' 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 'cddaar' does a car on the expression, followed by a car , followed by a cdr , followed by another cdr. If at any point the list is NIL , NIL is returned. If at anypoint a car operation is performed on an atom [as opposed to a list] an error is reported:

error: bad argument

Examples

(setq mylist '((((111A 111B) (112A 112B) (113A 113B))   ; make a 4-level list
                ((121A 121B) (122A 122B) (123A 123B))
                ((131A 131B) (132A 132B) (133A 133B))
                ((141A 141B) (142A 142B) (143A 143B)))

               (((211A 211B) (212A 212B) (213A 213B))   ; 2nd set
                ((221A 221B) (222A 222B) (223A 223B))
                ((231A 231B) (232A 232B) (233A 233B))
                ((241A 241B) (242A 242B) (243A 243B)))

               (((311A 311B) (312A 312B) (313A 313B))   ; 3rd set
                ((321A 321B) (322A 322B) (323A 323B))
                ((331A 331B) (332A 332B) (333A 333B))
                ((341A 341B) (342A 342B) (343A 343B)))

               (((411A 411B) (412A 412B) (413A 413B))   ; 4th set
                ((421A 421B) (422A 422B) (423A 423B))
                ((431A 431B) (432A 432B) (433A 433B))
                ((441A 441B) (442A 442B) (443A 443B)))

               (((511A 511B) (512A 512B) (513A 513B))   ; 5th set
                ((521A 521B) (522A 522B) (523A 523B))
                ((531A 531B) (532A 532B) (533A 533B))
                ((541A 541B) (542A 542B) (543A 543B)))))

(caaaar mylist)   ; returns 111A
(caaadr mylist)   ; returns (211A 211B)
(caadar mylist)   ; returns (121A 121B)
(caaddr mylist)   ; returns ((311A 311B) (312A 312B) (313A 313B))
(cadaar mylist)   ; returns (112A 112B)
(cadadr mylist)   ; returns ((221A 221B) (222A 222B) (223A 223B))
(caddar mylist)   ; returns ((131A 131B) (132A 132B) (133A 133B))
(cadddr mylist)   ; returns (((411A 411B) (412A 412B) (413A 413B))
                  ;          ((421A 421B) (422A 422B) (423A 423B))
                  ;          ((431A 431B) (432A 432B) (433A 433B))
                  ;          ((441A 441B) (442A 442B) (443A 443B)))

(cdaaar mylist)   ; returns (111B)
(cdaadr mylist)   ; returns ((212A 212B) (213A 213B))
(cdadar mylist)   ; returns ((122A 122B) (123A 123B))
(cdaddr mylist)   ; returns (((321A 321B) (322A 322B) (323A 323B))
                  ;          ((331A 331B) (332A 332B) (333A 333B))
                  ;          ((341A 341B) (342A 342B) (343A 343B)))
(cddaar mylist)   ; returns ((113A 113B))
(cddadr mylist)   ; returns (((231A 231B) (232A 232B) (233A 233B))
                  ;          ((241A 241B) (242A 242B) (243A 243B)))
(cdddar mylist)   ; returns (((141A 141B) (142A 142B) (143A 143B)))
(cddddr mylist)   ; returns ((((511A 511B) (512A 512B) (513A 513B))
                  ;           ((521A 521B) (522A 522B) (523A 523B))
                  ;           ((531A 531B) (532A 532B) (533A 533B))
                  ;           ((541A 541B) (542A 542B) (543A 543B))))

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

  Back to Top


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