# [plt-scheme] When does eqv? differ from eq? , from equal?

Woodhouse Gregory wrote:
>*
*>* I almost always perform tests with eq? or equal?, seldom (if ever)
*>* with eqv? . The Reference is a bit mysterious, saying (in section 3.1)
*>*
*>* Two values are eqv?
*>* <file:///Applications/PLT%20Scheme%20Full%20v4.1.0.3/doc/reference/booleans.html#%28def._%28%28quote._%7E23%7E25kernel%29._eqv%7E3f%29%29>
*>* if and only if they are eq?
*>* <file:///Applications/PLT%20Scheme%20Full%20v4.1.0.3/doc/reference/booleans.html#%28def._%28%28quote._%7E23%7E25kernel%29._eq%7E3f%29%29>,
*>* unless otherwise specified for a particular datatype.
*>*
*Which means you ought to use eqv? for characters and numbers.
A heuristic: If a members of a datatype have a unique representation on
the machine level,
then it is safe to use eq?. If two different representations can
represent the same (abstract) value,
then use eqv?.
For floating point numbers +0.0 and -0.0 have different representaions,
but both represent zero.
The fixnum 0 and the bignum 0 also have different representation, but
represent the same number.
Conclusion: Always use eqv? instead of eq? when comparing numbers.
Exception: If you in an algorithm can prove all numbers are
representable as, say, fixnums, then
you can use eq? -- but remember that the range of
fixnums may be different on other
implementations.
Characters can also have different representations - at least in some
implementations.
The subject pops up once in a while in comp.lang.scheme. One example of
such a thread
is:
http://groups.google.com/group/comp.lang.scheme/browse_thread/thread/201fd2d0723731c5/c57f5868525aa811?lnk=gst&q=eq%3F+eqv%3F#c57f5868525aa811
--
Jens Axel Søgaard