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:
What happens if you give it more than one operand, or none at all?> (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
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