Accessor rest

Syntax:

rest list tail

(setf (rest list) new-tail)

Arguments and Values:

list—a list, which might be a dotted list or a circular list.

tail—an object.

Description:

15.2.0 13rest performs the same operation as cdr, but mnemonically complements first. Specifically,

 (rest list) ≡ (cdr list)
 (setf (rest list) new-tail) ≡ (setf (cdr list) new-tail)

If \param{list} is a \term{cons}, \funref{rest} returns the portion that follows the first \term{element}. If \param{list} is the \term{empty list}, \funref{rest} returns the \term{empty list}. \macref{setf} may be used with \funref{rest} to change the \term{cdr} of a \term{non-empty} \term{list} (\ie a \term{cons}).

Examples:

 (rest '(1 2)) → (2)
 (rest '(1 . 2)) → 2
 (rest '(1)) → NIL
 (setq *cons* '(1 . 2)) → (1 . 2)
 (setf (rest *cons*) "two") → "two"
 *cons* → (1 . "two")

Side Effects:

None.

Affected By:

None.

Exceptional Situations:

None.

See Also:

cdr, nthcdr

Notes:

rest is often preferred stylistically over cdr when the argument is to being subjectively viewed as a list rather than as a cons.