Fundamentals of Computer Science I (CSC-151.02 2000F)

Boolean Values and Predicate Procedures

A Boolean value is a datum that reflects the outcome of a single yes-or-no test. For instance, if one were to ask Scheme to compute whether the empty list has five elements, it would be able to determine that it does not, and it would signal this result by displaying the Boolean value for ``no'' or ``false,'' which is #f. There is only one other Boolean value, the one meaning ``yes'' or ``true,'' which is #t. (These are called ``Boolean values'' in honor of the logician George Boole, who was the first to develop a satisfactory formal theory of them.)

A predicate is a procedure that always returns a Boolean value. A procedure call in which the procedure is a predicate performs some yes-or-no test on its arguments. For instance, the predicate number? -- the question mark is part of the name of the procedure -- takes one argument and returns #t if that argument is a number, #f if it does not. Similarly, the predicate even? takes one argument, which must be an integer, and returns #t if the integer is even and #f if it is odd. The names of most Scheme predicates end with question marks, and I recommend this useful convention even though it is not required by the rules of the programming language.

Some Basic Predicates

Scheme provides a few predicates that let you test the ``type'' of value you're working with.

Scheme provides one basic predicate for working with lists (other than the list? predicate).

Scheme provides a variety of predicates for testing equality.

Scheme also provides many numeric predicates.

Boolean Procedures

Another useful Boolean procedure is not, which takes one argument and returns #t if the argument is #f and #f if the argument is anything else. For example, one can test whether the square root of 100 is unequal to the absolute value of negative twelve by giving the command

(not (= (sqrt 100) (abs -12)))

If Scheme says that the value of this expression is #t, then the two numbers are indeed unequal.

Two other useful Boolean procedures are and and or. Can you guess what they do?


Monday, 4 September 2000 (Sam Rebelsky)

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at

Source text last modified Wed Sep 13 10:50:38 2000.

This page generated on Wed Sep 13 10:50:40 2000 by Siteweaver. Validate this page's HTML.

Contact our webmaster at