On Fri, May 21, 2010 at 4:57 AM, Mibu <[email protected]> wrote:
> I tried to use Long keys from the java.io.File/length method in a hash-
> map and failed to retrieve values using them. sorted-map is fine. The
> doc says hash-maps require keys that support .equals and .hashCode.
> Doesn't Long support those or am I missing something else?
>
Here's a repl session that explains the story...
(def len (.length (java.io.File. "repl.sh")))
(def mp (hash-map len :foo))
len
==> 306
mp
==> {306 :foo}
(class len)
==> java.lang.Long
(mp len)
==> :foo
(len mp)
==>java.lang.ClassCastException: java.lang.Long cannot be cast to
clojure.lang.IFn (NO_SOURCE_FILE:0)
; can't do that - len is a Long not a function like a keyword is (e.g. :len)
(mp 306)
==> nil ; cause 306 is not a long
(mp (long 306))
:foo ; yep!
-Rgds, Adrian
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en