[plt-scheme] When does eqv? differ from eq? , from equal?
On Mon, Oct 6, 2008 at 4:38 PM, Alan Watson <alan at alan-watson.org> wrote:
>> What is it in your opinion?
>
> That eq? belongs in Common Lisp but not in Scheme. (I think this is a
> variant of Godwin's law: all discussions of judgement in Scheme will end up
> at some point invoking Common Lisp.) Or, being more up to date, that eq?
> belongs in the R6RS, along with the fixnum and flonum libraries.
>
> Does anyone have any (correct and real) code that is too slow with eqv? but
> fast enough with eq?
Interesting. I always thought eqv? was the odd man out -- it takes
the time to equate 10000000000 with 10000000000, but not (list 1 2 3)
with (list 1 2 3). Whereas equal? and eq? seem to be fairly
consistent ends of the spectrum: equal? is extensional equality
(recursive comparison of values) and eq? is intensional equality
(direct comparison of pointers). I see eqv? as an ad hoc "happy
medium" between the two, taking the time to perform extensional
equality on bignums because it is often useful and rarely too costly,
but not anything else for reversed reasons.
At first glance, eqv? does seem equivalent to (or "close enough" to)
intensional equality on bignums, since we can't observe their
components by mutation. However, we can observe the differences in
space consumption between a list of bignums that are all eq? (not much
space used), versus a list of bignums that are all eqv? but not eq?
(potentially lots of space used).
Practically, I only use eq? when I really, really mean it; I use = for
(exact) numeric comparisons and try not to use equal? except in test
suites.
--
Carl Eastlund