Go to the first, previous, next, last section, table of contents.

Choosing Equality Predicates (Hunk I)

==================================================================
Hunk I starts here:
==================================================================

The reason that the = and eqv? predicates are needed is that the numeric system of Scheme is not quite as clean as it could be, for efficiency reasons.

Ideally, there would be exactly one copy of any numeric value, and all occurrences of that value would really be pointers to the same unique object. Then you could use eq? to compare numbers for identity, just as you can for other kinds of values. (For example, there would be just one floating-point number with the value 2.36529, and any computation that returned that floating-point value would return a pointer to that unique object. ((eq? 2.36529 2.36529) would return #t.)

Unfortunately, for numbers it would be too expensive to do this--it would require keeping a table of all of the numbers in the system, and probing that table to eliminate duplicate copies of the same values. As a concession to efficiency, Scheme allows multiple copies of the same number, and the = and eqv? predicates mask this wart in the language--they perform numeric comparisons when faced with numbers, so that you don't have to worry about whether two numbers with the same value are literally the same object.

eqv? thus tests whether two values are "equivalent," when two objects with the same numeric value are treated as "the same," like =, but all other objects are distinguished by their object identity, like eq?. In general,


Go to the first, previous, next, last section, table of contents.