The Grinnell Scheme Web: The pair?
procedure

Is there a type predicate that distinguishes pairs from non-pairs?

Yes. The pair? procedure is a predicate of arity 1. It returns the true Boolean value if given a pair, the false Boolean value if given anything else:

> (pair? 5)
#f
> (pair? #t)
#f
> (pair? (lambda (n) (+ n 1)))
#f
> (pair? (cons 1 2))
#t
> (pair? (cons #t (lambda (n) (+ n 1))))
#t
> (pair? (cons (cons 1 2) (cons 3 4)))
#t
What happens if you give it more than one operand, or none at all?

This is an error and your program will crash.

> (pair?)

ERROR: Wrong number of args to #<primitive-procedure pair?>
; in expression: (... pair?)
; in top level environment.


Next topic
Previous topic
Table of contents


This document is available on the World Wide Web as

http://www.math.grin.edu/~stone/scheme-web/pair-ques.html


created August 6, 1995
last revised December 29, 1995

Copyright 1995 by John David Stone (stone@math.grin.edu)