On Jan 13, 1:26 am, Allen Rohner <aroh...@gmail.com> wrote:
> Keys in a map that are of type long can't be looked up in a map using
> int literal syntax:
>
> user=> (def my_map { (java.lang.Long. "42") "foo"})
> #'user/my_map
>
> user=> my_map
> {42 "foo"}
>
> user=> (my_map 42)
> nil
>
> user=> (my_map (long 42))
> "foo"
>
> user=> (= 42 (java.lang.Long. "42"))
> true
>
> I found this behavior incredibly confusing, especially given the fact
> that ints and longs print the same.
>
> I believe this is a bug. Rich, do you agree?
>
No.
Hashmaps use hashCode and equals (i.e. not =), which are defined by
Java for Integer and Long:
user=> (.equals (java.lang.Integer. "42") (java.lang.Long. "42") )
false
Literals are going to have the smallest (bounded by Integer)
representative type.
In general, you should use uniform types for hash keys.
Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---