Clojure n00b here, but very impressed so far.
Rich Hickey wrote:
> There is some renaming/removing in this release:
>
> removed implement, use proxy
I just tried the new version and failed to adjust some of my code to the
changes. Specifically, I can't seem to implement java.util.Comparator
anymore for (sorted-map-by ).
I used to have:
(def compare-range
(implement [java.util.Comparator]
(compare [a b]
(stuff a b)) ; actually more complex...
(equals [a]
(= a compare-range))))
Which, as far as I can tell, should now be:
(def compare-range
(proxy [java.util.Comparator] []
(compare [a b]
(stuff a b)) ; actually more complex...
(equals [a]
(= a this))))
Which gets me:
java.lang.ClassFormatError: Duplicate method name&signature in class
file clojure/lang/Proxy__<ID>
I've reduced it to a trivial test for the REPL:
user=> (proxy [Object java.util.Comparator] []
(compare [a b] (if (< a b) -1 (if (> a b) 1 0))))
java.lang.ClassFormatError: Duplicate method name&signature in class
file clojure/lang/Proxy__1066
java.lang.ClassFormatError: Duplicate method name&signature in class
file clojure/lang/Proxy__1066
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.lang.ClassLoader.defineClass(ClassLoader.java:465)
at
clojure.lang.DynamicClassLoader.defineClass(DynamicClassLoader.java:33)
at clojure.fns.clojure.get_proxy_class__783.doInvoke(proxy.clj:187)
at clojure.lang.RestFn.invoke(RestFn.java:426)
at clojure.fns.user.fn__1465.invoke(Unknown Source)
at clojure.lang.AFn.applyToHelper(AFn.java:181)
at clojure.lang.AFn.applyTo(AFn.java:174)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2376)
at clojure.lang.Compiler.eval(Compiler.java:3385)
at clojure.lang.Repl.main(Repl.java:75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
However,
user=> (proxy [Object] []
(compare [a b] (if (< a b) -1 (if (> a b) 1 0))))
clojure.lang.Proxy__1464@11c19919
Seems to work fine.
Not specifying Object explicitly, like
user=> (proxy [java.util.Comparator] []
(compare [a b] (if (< a b) -1 (if (> a b) 1 0))))
produces identical results to being explicit.
What am I doing wrong? Or might this be a bug?
Thanks!
~phil
Oh, fantastic. That works great and makes stuff somewhat simpler.
> I should probably doc that...
Probably. In retrospect it seems an obvious thing to try, of course. :)
I'm not quite at the stage where I'm reading the Clojure source yet.
Getting there...
Thanks for the quick response!
~phil