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

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Mon Oct 6 13:00:24 EDT 2008

Marco Morazan wrote:
> My real question is why is there a difference for datatypes that are
> not mutable? AFAIK, for example, I can not dissect a bignum and make
> assignments to individual bigits. Would it not make more sense for eq?
> on two numbers to turn into a call to = ?
>   

The comparison operator eq? has a sligthly strange semantics in order to 
allow
implementations to make eq? really, really fast. For immediate 
datatypes, whose
values can be kept in a single machine register, an eq?-comparison can be
done by comparing two machine registers. If eq? to behave differently
for numbers, then all eq?-comparisons need to make that extra check.

Thus eq? is implementable as a simple register/pointer comparison (no matter
which kind of values it is given).

Due to the odd semantics of eq? the operator eqv? was included. That behaves
as you suggest.

Btw - this discussion om whether to choose eq? or eqv? to compare numbers,
is related to the choice between  eq-hashtables and equal-hashtables  where
numbers are used as keys. If some of the numbers are bignums, then it
is important to choose equal-hashtables.

-- 
Jens Axel Søgaard



Posted on the users mailing list.