The Grinnell Scheme Web: Booleans

What about a procedure that determines whether two integers are equal? It could return 1 or 0 to mean that they are or are not.

Good idea, but the 0-1 code isn't necessary. Scheme provides a data type precisely to indicate the result of such a two-way test. The two values of this type are called Booleans: There's the Boolean value that means ``true'' or ``yes'' (denoted by the Boolean literal #t) and the one that means ``false'' or ``no'' (denoted by #f).

A procedure that always returns a Boolean value, like the equality procedure that you envision, is called a predicate. Scheme provides a number of them as built-in procedures. By convention, most of them are initially bound to variables ending in question marks, such as zero? and even?.

Where does the name `Boolean' come from?

It's an homage to the logician and mathematician George Boole, who was the first to describe the values, operations, and laws of this data type systematically.

How can you get a procedure to return a Boolean value rather than an integer?

You make the last command in the body of the procedure a Boolean expression -- one of the two Boolean literals named above, or perhaps a call to one of the built-in predicates. By the way, you don't have to define your own equality procedure. It's one of the built-ins.

Are there Boolean variables, too?

A variable can have a value of any data type -- integer, Boolean, procedure, or one of the data types we haven't seen yet. There's no difference between a variable that happens to be have a Boolean value and one that has an integer value -- any variable can be used for either one.


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/Booleans.html


created July 1, 1995
last revised December 26, 1995

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