[plt-scheme] Another question: eq? and eqv?
On Dec 30, Greg Woodhouse wrote:
> I've been experimenting with mutable and immutable strings, thinking
> two immutable strings equal to "hello" might be eq? but mutable
> strings would not be. No luck.
The thing is that there is little guarantees for `eq?', and a bit more
on `eqv?'. Writing code that relies on
(eq? "foo" "foo") --> #f
is asking for trouble (which is probably true for `eqv?' too, in this
case).
> But your example works. In fact, on the machine I'm using right now
> (a Pentium-something or another) 29 works, but not 30.
One bit is used to mark a 32-bit word as an integer, and another bit
is used for the sign, which leaves you with 30 bits, which means that
2^30 is just a little to big to fit in:
> (eq? (expt 2 30) (expt 2 30))
#f
> (eq? (sub1 (expt 2 30)) (sub1 (expt 2 30)))
#t
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!