caaar, ..., cddddr - additional compositions of car and cdr
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme cxr)) ;R7RS
These twenty-four procedures are further compositions of car and
cdr on the same principles as
For example, caddr could be
(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
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.
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.
This page is part of the
It includes materials from the RnRS documents.
More information can be found at
Markup created by unroff 1.0sc, March 04, 2023.