XLISP cdaaar ... cddddr

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# 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 or 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, then NIL is returned. If at anypoint a car operation is performed on an atom [as opposed to a list] an error is signalled:

    error: bad argument

## Examples

    (setq mylist '((((111A 111B) (112A 112B) (113A 113B))   ; 1st set
                    ((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)))))

    (cdaaar mylist)  => (111B)
    (cdaadr mylist)  => ((212A 212B) (213A 213B))
    (cdadar mylist)  => ((122A 122B) (123A 123B))
    (cdaddr mylist)  => (((321A 321B) (322A 322B) (323A 323B))
                         ((331A 331B) (332A 332B) (333A 333B))
                         ((341A 341B) (342A 342B) (343A 343B)))
    (cddaar mylist)  => ((113A 113B))
    (cddadr mylist)      (((231A 231B) (232A 232B) (233A 233B))
                         ((241A 241B) (242A 242B) (243A 243B)))
    (cdddar mylist)  => (((141A 141B) (142A 142B) (143A 143B)))
    (cddddr mylist)  => ((((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 'c...r' functions are part of the historical Lisp functions. You may find it easier to work with the modern lisp functions like nth and nthcdr.

See also:

- Contents → List Functions
- Tutorials → Lisp Hints → List Accessors

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference