caaar, ..., cddddr - additional compositions of car and cdr
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme cxr)) ;R7RS
(caaar pair)
(caaar pair)
(caadr pair)
(cadar pair)
(caddr pair)
(cdaar pair)
(cdadr pair)
(cddar pair)
(cdddr pair)
(caaaar pair)
(caaadr pair)
(caadar pair)
(caaddr pair)
(cadaar pair)
(cadadr pair)
(caddar pair)
(cadddr pair)
(cdaaar pair)
(cdaadr pair)
(cdadar pair)
(cdaddr pair)
(cddaar pair)
(cddadr pair)
(cdddar pair)
(cddddr pair)
These twenty-four procedures are further compositions of car and
cdr on the same principles as caar(3scm). For example,
caddr could be defined by
(define caddr (lambda (x) (car (cdr (cdr x))))).
Arbitrary compositions up to four deep are provided.
Returns the contents of the car or cdr field of the pair which is the next to
last pair through the chain of pairs.
(cadar '(((a . b) . (c . d)) ((1 . 2) . (3 . 4)))) => c
(cddddr '(1 2 3 4 5 6)) => (5 6)
These compositions are increasingly harder to read and reason about. It is a
good idea to instead use a pattern matching library like (chibi match).
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed, the argument was not a pair or
one of the intermediate links of car and cdr fields was not a pair.
- R7RS
- The assertions described above are errors. Implementations may signal an
error, extend the procedure's domain of definition to include such
arguments, or fail catastrophically.
R4RS, IEEE Scheme, R5RS, R6RS, R7RS