Problem with Comparator

8 views
Skip to first unread message

Teemu Antti-Poika

unread,
Jun 22, 2008, 4:19:07 PM6/22/08
to Clojure
Hi folks,

I've just discovered Clojure (interesting stuff! Congrats!) and run
into something I could not figure out on my own. Here's a minimal
version of the problem:

(defn my-comparator [r1 r2]
(if (< r1 r2)
-1
(if (= r1 r2)
0
1)))

(sort '(1 6 5 4) my-comparator)

In REPL this results in:
user=> java.lang.IncompatibleClassChangeError
java.lang.IncompatibleClassChangeError
at clojure.fns.clojure.sort__669.invoke(boot.clj:1266)
at clojure.lang.AFn.applyToHelper(AFn.java:186)
at clojure.lang.AFn.applyTo(AFn.java:175)
at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:2569)
at clojure.lang.Compiler.eval(Compiler.java:3780)
at clojure.lang.Repl.main(Repl.java:75)

What's this about? Any ideas?

My version of clojure jar is the latest on sourceforge (at the time of
writing).

Rich Hickey

unread,
Jun 22, 2008, 4:25:12 PM6/22/08
to Clojure


On Jun 22, 4:19 pm, Teemu Antti-Poika <antti...@gmail.com> wrote:
> Hi folks,
>
> I've just discovered Clojure (interesting stuff! Congrats!) and run
> into something I could not figure out on my own. Here's a minimal
> version of the problem:
>
> (defn my-comparator [r1 r2]
> (if (< r1 r2)
> -1
> (if (= r1 r2)
> 0
> 1)))
>
> (sort '(1 6 5 4) my-comparator)
>
> In REPL this results in:
> user=> java.lang.IncompatibleClassChangeError
> java.lang.IncompatibleClassChangeError
>
> What's this about? Any ideas?
>

The comparator goes first:

(sort my-comparator '(1 6 5 4))
-> (1 4 5 6)

Rich

Teemu Antti-Poika

unread,
Jun 23, 2008, 12:58:09 AM6/23/08
to Clojure
On Jun 22, 11:25 pm, Rich Hickey <richhic...@gmail.com> wrote:
> On Jun 22, 4:19 pm, Teemu Antti-Poika <antti...@gmail.com> wrote:
>
> > (sort '(1 6 5 4) my-comparator)
>
> > In REPL this results in:
> > user=> java.lang.IncompatibleClassChangeError
> > java.lang.IncompatibleClassChangeError
>
> The comparator goes first:
>
> (sort my-comparator '(1 6 5 4))
> -> (1 4 5 6)
>
> Rich

And so it seems to go - my bad!

Sorry to waste your time with that one, but thanks! :)

Teemu
Reply all
Reply to author
Forward
0 new messages