[plt-scheme] Another question: eq? and eqv?
Greg-
On Dec 30, 2005, at 6:51 PM, Greg Woodhouse wrote:
> I understand that eq? is supposed to compare objects for identity
> (like
> comparing pointers) and equal? compares objects for value. I also
> understand that equal? recursively applies eqv? to the components of a
> structure. What is less clear to me is how eq? and eqv? differ.
> When is
> (eq? a b) different from (eqv? a b) ?
In addition to Jens' point from earlier (I'm not entirely sure that
Richard Fateman's answer is 100% correct, since he is building his a
and b via list, rather than literal expressions via quote) you should
also note the following:
If you read section 6.1 of R5RS very carefully, you'll find that eq?
is allowed to discriminate between some objects that are otherwise
indistinquishable. For example when a and b are numbers, (eq? a b)
might return false even if (= a b) returns true. (eqv? a b) is meant
to do the "right" thing in those cases.
I believe that the basis for this distinction is that some numbers,
such as bignums, are complex structures for which a full equivalence
predicate may be inefficient, while the eq? procedure is intended to
always be a fast comparison (of say two pointers or immediate values).
Of course, not all of the languages in DrScheme are meant to conform
to R5RS, so using it as your standard might be a mistake, depending
on what you're doing. But I don't think doing so will lead you wrong
on this point.
-Felix