On 6 Nov, 07:25, 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.)
>
> 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

I don't have the book yet so I don't know what Stuarts intention was
with the example but here are my thoughts on the matter.
Dispatching based on type (class) makes more sense for java objects
such as a String than the Clojure data structures since Clojure
focuses more on value-equals semantics (which in dispatch would be
sort of like duck typing) than identity comparison.
For a discussion about dispatching based on type see this old thread:
http://groups.google.com/group/clojure/browse_thread/thread/74d430f8e4353725/d16b548d4d46aab0

/mac
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to