================================================================== Hunk I starts here: ==================================================================
The reason that the
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
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
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
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,"
=, but all other objects are distinguished by their
object identity, like
eq?. In general,
eq?is useful for fast identity (same object) comparisons of non-numbers,
=performs numeric comparisons on numbers,
eq?, but treats copies of the same number as though they were the same object, and
equal?performs a "deep" comparison of the structure of data structures. (It uses
eqv?for components that are numbers.)