Aha, I'm sorry for my laziness and spamming. {:a 1} is not a hash-map.
I guess there is some reason of performance about this... Anyway, as
mac pointed out, dispatching based on types will be inappropriate to
clojure data structures. Thank you mac for the thread link~
user> (class {:a 1})
#=clojure.lang.PersistentArrayMap
On 11월6일, 오후9시22분, Chanwoo Yoo <[EMAIL PROTECTED]> wrote:
> Thanks~ "clojure.lang.PersistentHashMap" works~ :) But I feel
> something is strange.. See next code, especially arrowed line.
>
> user> clojure.lang.PersistentHashMap
> #=clojure.lang.PersistentHashMap
> user> (= (class {:a 1 :b 2}) clojure.lang.PersistentHashMap)
> true
> user> (= (class {}) clojure.lang.PersistentHashMap)
> true
> user> (= (class {:a 1 :b 2}) (class {}))
> true
> user> (= (class {:a 1}) (class {})) ;; <=
> false
> user> (= (class {:a 1}) clojure.lang.PersistentHashMap) ;; <=
> false
> user> (= (class (hash-map :a 1)) clojure.lang.PersistentHashMap)
> true
> user> (= (class (hash-map :a 1)) (class {:a 1})) ;; <=
> false
> user> (:a {:a 1})
> 1
>
> Is {:a 1} not a hash-map? It seems that there is some inconsistency...
>
> On 11월6일, 오후4시27분, "Michael Wood" <[EMAIL PROTECTED]> wrote:
>
> > On Thu, Nov 6, 2008 at 8:25 AM, Chanwoo Yoo <[EMAIL PROTECTED]> wrote:
>
> > > Hi all. In Stuart's book - Programming Clojure, there is a multi
> > > method like following:
>
> > > (defmulti blank? class)
> > > (defmethod blank? String [s] (every? #{\space} s))
> > > (defmethod blank? nil [_] true)
>
> > > After reading the method, I was curious about type or class of native
> > > data structures of Clojure. So I typed next code in slime. Hmm.. I
> > > didn't understand why classes of {:a 1} and {} are not same. Like
> > > Stuart's code, to make multi method branching based on clojure data
> > > structure type(map, vector, list), what symbol should I use? (Like
> > > String for "string", Is there a Map for {:a 1}? I tried
> > > PersistentHashMap, HashMap, Map, so on.. I didn't find it.)
>
> > I think what you're looking for is "clojure.lang.PersistentHashMap"
> > instead of just "PersistentHashMap".
>
> > user=> String
> > java.lang.String
> > user=> PersistentHashMap
> > java.lang.Exception: Unable to resolve symbol: PersistentHashMap in this
> > context
> > [...]
> > user=> clojure.lang.PersistentHashMap
> > clojure.lang.PersistentHashMap
> > user=>
>
> > I don't know much about Clojure, though, so I suspect there is better
> > advice than the above :)
>
> > > user> (= (class "abc") String)
> > > true
> > > user> (class {:a 1 :b 2})
> > > #=clojure.lang.PersistentHashMap
> > > user> (class {})
> > > #=clojure.lang.PersistentHashMap
> > > user> (= (class {:a 1}) (class {}))
> > > false
> > > user> (= (class {:a 1}) (class {:b 2}))
> > > true
>
> > That seems rather strange to me too.
>
> > --
> > Michael Wood <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---