================================================================== Hunk G starts here: ==================================================================
[ Some of this stuff needs to come before recursion over various data structures... we use a few predicates there. Fix. ] Since a pointer can point to any kind of thing, it's often good to know what kind of thing it does point to. For example, you might have a mixed list of different kinds of things, and want to go through the list, doing a different operation for each kind of object you encounter. For this, Scheme provides type predicates, which are procedures which test to see whether the pointed-to object is of a particular type.
You also often want to know whether two values refer to the same object, or to data structures with the same structure. For this, Scheme provides equality predicates.
These procedures are called "predicates" because they test whether
a property is true of a value, and return a yes-or-no answer--that
is, the boolean
#t or the boolean
#f. (This is like a
"predicate" in formal logic, which is a kind of statement with
a "truth value" that depends on its arguments.)
The names of predicates generally end with a question mark, to signify that they return a boolean. When you write your own programs, it's good style to end the names of boolean-valued (true/false) functions with a question mark.
(An exception to this rule is the standard numeric
comparison predicates like
the rule, they should have question marks after their names, but
they're used very frequently and people generally recognize that
they're predicates. We don't bother with question marks in their
names, because it would clutter up arithmetic expressions.)