Reputation: 577
I have just started reading The Little schemer. I have some problem understanding some words.
In page 27 it says,
The Law of Eq?
The primitive eq? takes two arguments. Each must be a non-numeric atom."
And a footnote says: In practice, some numbers may be arguments of eq?
I am using racket-minimal as my scheme interpreter. It evaluates (eq? 10 10)
to #t
.
There are many similar type of problems in TOYS chapter.
What did the author mean by that must(marked as bold) and the footnote?
Upvotes: 1
Views: 269
Reputation: 1567
Scheme's true identity predicate is eqv?
. Eq?
is an optimized version that is allowed to report #f
instead of #t
when applied to numbers, characters, or procedures. Most Scheme implementations of eq?
do the right thing on small exact numbers (called "fixnums"), characters, and procedures, but fall down on larger numbers or numbers of other types.
So saying "MUST" means that you get only partly predictable results if you apply eq?
to a number; the footnote means that in some cases (and this typically includes 10) you will get away with it. For details on what various Schemes actually do with fixnums, see FixnumInfo at the R7RS development site.
Upvotes: 1
Reputation: 48765
It's traditional to embed some primitive data types such as low integers and characters in the pointer itself making those datatypes eq?
even when the data came to be in the source at different times / points in source. However, numbers can be any size so even if number upto a certain implementation dependent size at some point they will be to big for the pointer. When you try (eq? 10000000000 10000000000)
it might be #f
on 32 bits systems and #t
in 64 bit systems while (eqv? 10000000000 10000000000)
is #t
in any system.
Upvotes: 2