Re: [racket-users] Are fixnums guaranteed to be `eq?` whenever they are `=`/`equal?` ?

2016-03-14 Thread Matthew Flatt
At Mon, 14 Mar 2016 19:59:51 -0400, Tony Garnock-Jones wrote:
> On 03/14/2016 07:53 PM, Matthew Flatt wrote:
> > [fixnum eqness is guaranteed by the docs.
> > [...] And keywords [are also guaranteed].
> > [...] [And] Booleans, void, and characters with a scalar value under 256.
> > 
> > Opaque objects like custodians and inspectors are also `equal?` only
> > when they are `eq?`, but I'm not sure if that's the kind of thing
> > you're looking for.
> 
> Great, thank you.
> 
> I am building up a list of things safe-to-use-eq? on because I want to
> sometimes skip expensive hashconsing-by-equal?. If I know that eq? is
> already the right predicate, then the value is effectively already
> hashconsed.
> 
> If there were a predicate `eq-applicable?` (or something), I could skip
> using a hand-coded list of special cases, and could systematically avoid
> the expense of hashconsing for a wider range of values.
> 
> Any thoughts on the possibility of such a predicate existing in Racket? :-)

That sounds like a good addition. I'll put it on my list.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Are fixnums guaranteed to be `eq?` whenever they are `=`/`equal?` ?

2016-03-14 Thread Matthew Flatt
At Mon, 14 Mar 2016 19:43:51 -0400, Tony Garnock-Jones wrote:
> Can I rely on the truth of the following:
> 
>   (implies (and (fixnum? x) (fixnum? y) (= x y))
>(eq? x y))
> 
> ?

Yes, that's guaranteed by the docs.


> I know I can rely on something similar for symbols.

And keywords.


> What other sorts of values can I rely on eq? being an appropriate
> equivalence predicate for?

Booleans, void, and characters with a scalar value under 256.

Opaque objects like custodians and inspectors are also `equal?` only
when they are `eq?`, but I'm not sure if that's the kind of thing
you're looking for.

Literal numbers, characters, strings, byte strings, or regular
expressions in a program are also `eq?` when they are `equal?`, since
they're interned. That's an property of where the values came from,
though, as opposed to a property of the kind of value.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.