pair? - test if an object is a pair
(import (rnrs)) ;R6RS
(import (rnrs base)) ;R6RS
(import (scheme r5rs)) ;R7RS
(import (scheme base)) ;R7RS
The pair? predicate returns #t if obj is a pair, and
otherwise returns #f.
Returns a single boolean object as per the description.
(pair? '(a . b)) => #t
(pair? '(a b c)) => #t
(pair? '()) => #f
(pair? '#(a b)) => #f
One of the most common uses of pair? is to destructure large data
structures, to extract parts of them and to verify their structure. Larger
structures are more conveniently destructured using a pattern matching library
such as (chibi match).
The pair? predicate allows a program to walk over a data structure built
from pairs. It also allows programs to protect themselves against invalid
calls to procedures that expect pairs, such as car(3scm).
Not all predicates are guaranteed to be disjoint from this predicate.
Implementations are free to use pairs to construct some of the kinds of
objects described in the Scheme reports, such as conditions and promises. The
disjointness of predicates differs between the Scheme reports.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed.
- R7RS
- The assertions 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
Lisp has always tagged objects with a type. Early Lisp used pattern matching, an
example of which is maplist from MIT AI Memo No. 4 (1958 or 1959). Early Lisp
programs written in S-expressions used the null and atom predicates to test
for the inverse of pair?, as in MIT AI Memo No. 14 (1959 or 1960). This
style seems to have continued even until Scheme (MIT AI Memo No. 349, December
1975). The first Scheme report to have pair? is RRRS (MIT AI Memo No.
848, August 1985), and it was the first Scheme report to not assume an
underlying MacLISP implementation.