car x → object | (setf (x object) new-object)
cdr x → object | (setf (x object) new-object)
caar x → object | (setf (x object) new-object)
cadr x → object | (setf (x object) new-object)
cdar x → object | (setf (x object) new-object)
cddr x → object | (setf (x object) new-object)
caaar x → object | (setf (x object) new-object)
caadr x → object | (setf (x object) new-object)
cadar x → object | (setf (x object) new-object)
caddr x → object | (setf (x object) new-object)
cdaar x → object | (setf (x object) new-object)
cdadr x → object | (setf (x object) new-object)
cddar x → object | (setf (x object) new-object)
cdddr x → object | (setf (x object) new-object)
caaaar x → object | (setf (x object) new-object)
caaadr x → object | (setf (x object) new-object)
caadar x → object | (setf (x object) new-object)
caaddr x → object | (setf (x object) new-object)
cadaar x → object | (setf (x object) new-object)
cadadr x → object | (setf (x object) new-object)
caddar x → object | (setf (x object) new-object)
cadddr x → object | (setf (x object) new-object)
cdaaar x → object | (setf (x object) new-object)
cdaadr x → object | (setf (x object) new-object)
cdadar x → object | (setf (x object) new-object)
cdaddr x → object | (setf (x object) new-object)
cddaar x → object | (setf (x object) new-object)
cddadr x → object | (setf (x object) new-object)
cdddar x → object | (setf (x object) new-object)
cddddr x → object | (setf (x object) new-object)
cadr
: [ˈkaˌdə r]
caddr
: [ˈkadə ˌdə r]
or [ˈkaˌd.udə r]
cdr
: [ˈk.uˌdə r]
cddr
: [ˈk.udə ˌdə r]
or [ˈkəˌd.udə r]
x—a list.
object—an object.
new-object—an object.
If x is a cons, car
returns the car
of that cons. If x is nil
, car
returns nil
.
If x is a cons, cdr
returns the cdr
of that cons. If x is nil
, cdr
returns nil
.
Functions are provided which perform compositions of up to four
car
and cdr
operations. Their names consist of
a C
, followed by two, three, or four occurrences of A
or D
,
and finally an R
. The series of A
's and D
's in each
function's name is chosen to identify the series of
car
and cdr
operations that is performed by the function.
The order in which the A
's and D
's appear is the inverse of the
order in which the corresponding operations are performed. The next figure
defines the relationships precisely.
|
Figure 14.6: CAR and CDR variants
setf
can also be used with any of these functions to change an
existing component of x, but setf
will not make new
components. So, for example, the car of a cons
can be assigned with setf
of car
,
but the car of nil
cannot be assigned with setf
of car
.
Similarly, the car of the car of a cons whose car
is a cons can be assigned with setf
of caar
,
but neither nil
nor a cons whose car is nil
can be assigned
with setf
of caar
.
The argument x is permitted to be a dotted list or a circular list.
(car nil) → NIL (cdr '(1 . 2)) → 2 (cdr '(1 2)) → (2) (cadr '(1 2)) → 2 (car '(a b c)) → A (cdr '(a b c)) → (B C)
The functions car
and cdr
should signal type-error
if they receive an argument which is not a
list. The other functions (caar
, cadr
,
... cddddr
) should behave for the purpose of
error checking as if defined by appropriate calls to car
and
cdr
.
The car of a cons can also be altered by using rplaca
,
and the cdr of a cons can be altered by using rplacd
.
(car x) ≡ (first x) (cadr x) ≡ (second x) ≡ (car (cdr x)) (caddr x) ≡ (third x) ≡ (car (cdr (cdr x))) (cadddr x) ≡ (fourth x) ≡ (car (cdr (cdr (cdr x))))