[plt-scheme] Another question: eq? and eqv?

From: Eli Barzilay (eli at barzilay.org)
Date: Fri Dec 30 19:17:15 EST 2005

On Dec 30, 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) ?

See the R5RS text -- the bottom line is that `eq?' is comparing actual
objects, so it is guaranteed to be constant time etc etc.  But it can
also expose implementation details, like

  (eq? (expt 2 40) (expt 2 40))

is false in mzscheme if it was compiled on a 32-bit platform, and true
on a 64-bit.  OTOH,

  (eqv? (expt 2 40) (expt 2 40))

will always return #t, since it's just an implementation detail that
they are different.  Various Schemes can do all kinds of similarly
crazy stuff, and `eqv?' is supposed to be more, um, reasonable.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.