pair? - test if an object is a pair

LIBRARY

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

SYNOPSIS

(pair? obj)

DESCRIPTION

The pair? predicate returns #t if obj is a pair, and otherwise returns #f.

RETURN VALUES

Returns a single boolean object as per the description.

EXAMPLES

(pair? '(a . b))  =>  #t
(pair? '(a b c))  =>  #t
(pair? '())       =>  #f
(pair? '#(a b))   =>  #f

APPLICATION USAGE

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).

RATIONALE

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).

COMPATIBILITY

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.

ERRORS

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.

SEE ALSO

car(3scm), cons(3scm)

STANDARDS

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

HISTORY

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.

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.