Re: (.containsKey {:one 1} :one) throws Exception

2012-03-04 Thread Alf Kristian Støyle
Thanks for the feedback guys. I have submitted a jira issue for the bug:

http://dev.clojure.org/jira/browse/CLJ-944

By the way, tried this with Clojure 1.2.1, and there it works fine.

Cheers,
Alf


On Sat, Mar 3, 2012 at 16:11, Herwig Hochleitner hhochleit...@gmail.comwrote:

 Looks like the type inferencer inserts a cast to PersistentHashMap,
 where it should only cast to clojure.lang.Associative (the interface
 on which .containsKey is defined).
 Also, the type inferencer picks up the wrong type from the literal,
 but that wouldn't matter, if it would always cast to the most general
 class on which a method call can be resolved.

 Can someone verify that explaination?

 kind regards

 --
 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
 Note that posts from new members are moderated - please be patient with
 your first post.
 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


-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

(.containsKey {:one 1} :one) throws Exception

2012-03-03 Thread Alf Kristian Støyle
Hi guys, I am wondering why this does not work:

(.containsKey {:one 1} :one)
;= ClassCastException clojure.lang.PersistentArrayMap cannot be cast to
clojure.lang.PersistentHashMap

The map is a:

(class {:one 1})
;= clojure.lang.PersistentArrayMap

And a PersistentArrayMap does have a containsKey method (
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentArrayMap.java#L95
).

I can even find the method:

(filter #(= containsKey (.getName %)) (.getMethods (class {:one 1})))
;= (#Method public boolean
clojure.lang.PersistentArrayMap.containsKey(java.lang.Object))

Should this not be a normal reflective method lookup, why do I get a
ClassCastException?

It does work if the map gets big enough:

(.containsKey {1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9} 1)
;= true

But at this point its a different collection:

(class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})
;= clojure.lang.PersistentHashMap

Cheers,
Alf

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

Re: (.containsKey {:one 1} :one) throws Exception

2012-03-03 Thread Bronsa
not sure why, but this works:

user= (.containsKey ^clojure.lang.Associative {:one 1} :one)
true


2012/3/3 Alf Kristian Støyle alf.krist...@gmail.com

 Hi guys, I am wondering why this does not work:

 (.containsKey {:one 1} :one)
 ;= ClassCastException clojure.lang.PersistentArrayMap cannot be cast to
 clojure.lang.PersistentHashMap

 The map is a:

 (class {:one 1})
 ;= clojure.lang.PersistentArrayMap

 And a PersistentArrayMap does have a containsKey method (
 https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentArrayMap.java#L95
 ).

 I can even find the method:

 (filter #(= containsKey (.getName %)) (.getMethods (class {:one 1})))
 ;= (#Method public boolean
 clojure.lang.PersistentArrayMap.containsKey(java.lang.Object))

 Should this not be a normal reflective method lookup, why do I get a
 ClassCastException?

 It does work if the map gets big enough:

 (.containsKey {1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8, 9 9} 1)
 ;= true

 But at this point its a different collection:

 (class {1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9})
 ;= clojure.lang.PersistentHashMap

 Cheers,
 Alf

 --
 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
 Note that posts from new members are moderated - please be patient with
 your first post.
 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

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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

Re: (.containsKey {:one 1} :one) throws Exception

2012-03-03 Thread Herwig Hochleitner
Looks like the type inferencer inserts a cast to PersistentHashMap,
where it should only cast to clojure.lang.Associative (the interface
on which .containsKey is defined).
Also, the type inferencer picks up the wrong type from the literal,
but that wouldn't matter, if it would always cast to the most general
class on which a method call can be resolved.

Can someone verify that explaination?

kind regards

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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