I think you might be using comparator incorrectly. It appears to expect a
function that returns a true/false value:
user> (source comparator)
(defn comparator
"Returns an implementation of java.util.Comparator based upon pred."
{:added "1.0"}
[pred]
(fn [x y]
(cond (pred x y) -1 (pred y x) 1 :else 0)))
So something like this might work:
user> (def string-comparator
(comparator (fn [a b]
(neg? (.compareTo a b)))))
#'user/string-comparator
user> (string-comparator "a" "b")
-1
user> (string-comparator "b" "a")
1
user> (string-comparator "a" "a")
0
Doesn't seem very useful though.
Regards,
Stuart
On 20 November 2011 14:28, Randy Pensinger <[email protected]> wrote:
> I am having a lot of trouble finding a place to mention a possible
> clojure bug. Is this it?
>
> I am trying to write a custom comparator, but the comparator never
> seems to work. I simplified the comparator below.
>
> user=> (def stringComparator
> (comparator (fn [a b]
> (do
> (println (str "comparing '" a "' to '" b "'"))
> (.compareTo a b)))))
> #'user/stringComparator
> user=> (.compare stringComparator "b" "a")
> comparing 'b' to 'a'
> -1
> user=> (compare "b" "a")
> 1
> user=> (clojure-version )
> "1.3.0"
>
>
> Am I doing something wrong?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> 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
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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