Hi all,

can anyone explain why these 2 are different given the same protocol (the only difference is the swapped ordering)?

(defprotocol FOO
 (bar [this a]
      [this a b]) )

(extend-protocol FOO  ;;THIS WORKS
(Class/forName "[D")
(bar
 ([_ a] a)
 ([_ a b] (+ a b)))
String
(bar
 ([_ a] (str a))
 ([_ a b]  (str a b))))


(extend-protocol FOO  ;;THIS WON'T COMPILE
String
(bar
 ([_ a] (str a))
 ([_ a b]  (str a b)))
(Class/forName "[D")
(bar
 ([_ a] a)
 ([_ a b] (+ a b))) )

CompilerException java.lang.UnsupportedOperationException: nth not supported on this type: Character, compiling:(NO_SOURCE_PATH:1:1)

it seems that the extension points include arrays, the ordering matters!!! The extension to array has to come first otherwise it won't even compile...Moreover, and possibly for the same reason, multiple extensions for different array-types fails with the same exception. for example while the following works:

(extend-protocol FOO
(Class/forName "[D")
(bar
 ([_ a] a)
 ([_ a b] (+ a b))) )

trying to add more types fails:

(extend-protocol FOO
(Class/forName "[D")
(bar
 ([_ a] a)
 ([_ a b] (+ a b)))
(Class/forName "[F")
(bar
 ([_ a] a)
 ([_ a b] (+ a b))) )

CompilerException java.lang.UnsupportedOperationException: nth not supported on this type: Character, compiling:(NO_SOURCE_PATH:1:1)

Jim

--
--
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to