car(3scm) Scheme Programmer's Manual car(3scm)

car, cdr - the car or cdr field of a pair (head and tail)

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme base))              ;R7RS

(car pair)
(cdr pair)

Returns the contents of the car or cdr field of a pair.

These procedures can also be used with lists, which in Scheme are linked lists of pairs. The car procedure returns the head of a list. The cdr procedure returns the tail of a list.

Returns the contents of the car or cdr field of pair.

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The argument is not a pair.
&assertion (R6RS)
The wrong number of arguments was passed.
R7RS
The situations 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

(car '(a b c))      => a
(car '((a) b c d))  => (a)
(car '(1 . 2))      => 1
(car '())           => &assertion exception
(cdr '((a) b c d))  => (b c d)
(cdr '(1 . 2))      => 2
(cdr '())           => &assertion exception

cons(3scm), list-ref(3scm), pairs(7scm), set-car!(3scm)

Present in MIT AI Memo No. 1 (September 1958).

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.
2020-04-18