car, cdr - the car or cdr field of a pair (head and tail)
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme base)) ;R7RS
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
Present in MIT AI Memo No. 1 (September 1958).