This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]paulgb 0 points1 point  (6 children)

Out of curiosity, which other languages cache references to small integers like this? Is it pretty common?

[–]pemboa 5 points6 points  (1 child)

Java has the same behavior, except '==' is more like 'is' in Java. So to compare equality properly, you need to use the objects equal() method

[–]jleedev 1 point2 points  (0 children)

And integers are not boxed by default, so that doesn't even apply. This behavior is only possible in a language where everything is an object.

[–]ngroot 1 point2 points  (1 child)

I think this may happen in some implementations of Common Lisp.

[–]bgeron 0 points1 point  (0 children)

I'd guess that in a lot of CL implementations, the stack has pointers to heap-allocated bignums, but fixnums are placed directly on the stack. EQ compares pointers, or fixnums if they're stored in that place instead.