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

caaaar ... cadddr


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

Syntax

(caaaar expr)
(caaadr expr)
(caadar expr)
(caaddr expr)
(cadaar expr)
(cadadr expr)
(caddar expr)
(cadddr expr)
expr - a list or list expression
returns - the result of the last car function

Description

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

error: bad argument

The 'cadddr' function returns the same result as the fourth function.

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)))))

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

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:

  Back to Top


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