The Grinnell Scheme Web: The
boolean? procedure

So you use the boolean? predicate to distinguish Boolean values from values of other types?

That's right:

> (boolean? #t)
#t
> (boolean? #f)
#t
> (boolean? 0)
#f
> (boolean? (lambda (augend) (+ augend 3)))
#f
> (boolean? boolean?)
#f
> (boolean? (boolean? boolean?))
#t
The ``true'' and ``false'' Boolean values are Booleans. Zero is not. A procedure that adds 3 to its operand is not a Boolean. The boolean? procedure itself is not a Boolean. And finally ...

That last example needs some explaining, all right. What does it mean?

Evaluate it from the innermost parentheses outwards -- that's what Scheme does. The next-to-last example says that boolean? is not itself a Boolean value -- it's a procedure. So the expression (boolean? boolean?) has the value ``false.'' But that is a Boolean value, so (boolean? (boolean? boolean?)) has the value ``true.''

That's twisted.

I have to admit that that particular example is mainly for show. But it's also a warning about the language that you're learning: Scheme is a language in which it's easy to construct intricate reflexive and self-referential structures, and some of these twisted-seeming constructions are going to be far more useful than this light-hearted example.


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/boolean-ques.html


created July 1, 1995
last revised December 26, 1995

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