Hi everyone,

here is an odd one for you...I've got this tiny protocol:

(defprotocol Normalisable
(normalise [this transform-fn]
                  [this transform-fn limits]))

now, I'd like to have it extended to clojure native data-structures; no problem:

(extend-protocol Normalisable
java.lang.Number
(normalise
 ([this transform] (normalise this transform [10 -10 1 -1]))
 ([this transform limits] (apply transform this limits)))
clojure.lang.IPersistentVector
(normalise
([this transform]
   (let [top (apply max this)
         bottom (apply min this)]
   (mapv #(normalise % transform [top bottom]) this)) )
([this transform limits]
   (normalise this #(transform % limits))) )
clojure.lang.IPersistentSet
(normalise
([this transform]
   (let [top (apply max this)
         bottom (apply min this)]
 (persistent!
(reduce #(conj! %1 (normalise %2 transform [top bottom])) (transient #{}) this))))
([this transform limits]
   (normalise this #(transform %1 %2 %3 (first limits) (second limits)))) )
  )

So far so good...now I'd like to have it extended to arrays. I added the following to my 'extend-protocol' form:

(Class/forName "[D")
(normalise
([this transform]
   (let [top (apply max this)
         bottom (apply min this)]
(amap ^doubles this idx ret (normalise (aget ^doubles this idx) transform [top bottom]))))
([this transform limits]
   (normalise this #(transform % limits))))

and this throws this where the 'extend-protocol' form starts:

CompilerException java.lang.UnsupportedOperationException: nth not supported on this type: *Character*, compiling: (line 27)

if I replace (Class/forName "[D") with (class (double-array 1)) the error is slightly different:

CompilerException java.lang.UnsupportedOperationException: nth not supported on this type: *Symbol*, compiling: (line 27)

what on earth is going on? What character and what symbol is the error referring to? And where is nth being called?

the stack trace is the following but it's not very helpful (at least not to me!):

Compiler.java:6380 clojure.lang.Compiler.analyze
               Compiler.java:6322 clojure.lang.Compiler.analyze
               Compiler.java:2879 clojure.lang.Compiler$MapExpr.parse
               Compiler.java:6369 clojure.lang.Compiler.analyze
               Compiler.java:6322 clojure.lang.Compiler.analyze
               Compiler.java:3624 clojure.lang.Compiler$InvokeExpr.parse
               Compiler.java:6562 clojure.lang.Compiler.analyzeSeq
               Compiler.java:6361 clojure.lang.Compiler.analyze
               Compiler.java:6322 clojure.lang.Compiler.analyze
Compiler.java:5708 clojure.lang.Compiler$BodyExpr$Parser.parse
               Compiler.java:5139 clojure.lang.Compiler$FnMethod.parse
               Compiler.java:3751 clojure.lang.Compiler$FnExpr.parse
               Compiler.java:6558 clojure.lang.Compiler.analyzeSeq
               Compiler.java:6361 clojure.lang.Compiler.analyze
               Compiler.java:6616 clojure.lang.Compiler.eval
               Compiler.java:6608 clojure.lang.Compiler.eval
               Compiler.java:7064 clojure.lang.Compiler.load
               Compiler.java:7020 clojure.lang.Compiler.loadFile
                      RT.java:318 clojure.lang.RT$3.invoke
                 NO_SOURCE_FILE:1 user/eval252
               Compiler.java:6619 clojure.lang.Compiler.eval
               Compiler.java:6582 clojure.lang.Compiler.eval
                    core.clj:2852 clojure.core/eval
                     main.clj:259 clojure.main/repl[fn]
                     main.clj:259 clojure.main/repl[fn]
                     main.clj:277 clojure.main/repl[fn]
                     main.clj:277 clojure.main/repl
                 RestFn.java:1096 clojure.lang.RestFn.invoke
interruptible_eval.clj:56 clojure.tools.nrepl.middleware.interruptible-eval/evaluate[fn]
                     AFn.java:159 clojure.lang.AFn.applyToHelper
                     AFn.java:151 clojure.lang.AFn.applyTo
                     core.clj:617 clojure.core/apply
                    core.clj:1788 clojure.core/with-bindings*
                  RestFn.java:425 clojure.lang.RestFn.invoke
interruptible_eval.clj:41 clojure.tools.nrepl.middleware.interruptible-eval/evaluate interruptible_eval.clj:171 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval[fn]
                    core.clj:2330 clojure.core/comp[fn]
interruptible_eval.clj:138 clojure.tools.nrepl.middleware.interruptible-eval/run-next[fn]
                      AFn.java:24 clojure.lang.AFn.run
ThreadPoolExecutor.java:1145 java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java:615 java.util.concurrent.ThreadPoolExecutor$Worker.run
                  Thread.java:722 java.lang.Thread.run
Caused by: java.lang.UnsupportedOperationException: nth not supported on this type: Character
                      RT.java:857 clojure.lang.RT.nthFrom
                      RT.java:807 clojure.lang.RT.nth
             core_deftype.clj:758 clojure.core/emit-hinted-impl[fn]
                    core.clj:2487 clojure.core/map[fn]
                  LazySeq.java:42 clojure.lang.LazySeq.sval
                  LazySeq.java:60 clojure.lang.LazySeq.seq
                      RT.java:484 clojure.lang.RT.seq
                      RT.java:537 clojure.lang.RT.countFrom
                      RT.java:530 clojure.lang.RT.count
                     Cons.java:49 clojure.lang.Cons.count
               Compiler.java:6352 clojure.lang.Compiler.analyze

can anyone help with this? the thing that drives me crazy is the fact that if I do the following in a separate namespace, it compiles just fine!

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

(extend-protocol FOO
(Class/forName "[D")
(bar
([this a] 1)
([this transform limits] 2)))


thanks in advance  :)

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