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

LIBRARY

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

SYNOPSIS

(car pair)
(cdr pair)

DESCRIPTION

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.

RETURN VALUES

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

ERRORS

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.

STANDARDS

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

EXAMPLES

(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

SEE ALSO

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

HISTORY

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

AUTHORS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.


Markup created by unroff 1.0sc,    March 04, 2023.