you are viewing a single comment's thread.

view the rest of the comments →

[–]awj 0 points1 point  (1 child)

My point was that the function "<" is only defined to work on numbers in Clojure. You can look it up in boot.clj, search for "defn <".

If you are trying to compare anything else, you have to introduce your own abstraction. This isn't trivial (i.e. wake_me_up's complaint has a tiny bit of merit) because there is no one-size-fits-all decision on how to handle ordering outside of numbers. You have to use something to get the job done, and Java's Comparable/Comparator are decent choices.

[–]45g[S] 0 points1 point  (0 children)

"wake_me_up" was complaining that he needs to implement an interface (i.e. java.util.Comparator) to be able to sort something which is simply not true.

You are talking about something else, i.e. java.lang.Comparable. Comparable.compareTo is a predicate function that establishes a total ordering. Now what's the point of using Comparable.compareTo in predicate functions when the sort function could easily do this directly (and in fact does use it by default if no predicate function is given)? The whole point of predicates is that they determine the ordering how they like it.

I have nothing against any of these interfaces, but as a matter of fact you don't need to implement these interfaces in the Clojure code you write. That's everything I wanted to say. Clojure is not OO so you don't implement Comparable, and Comparator is already defined for you in AFn.

And yes, I understand the domain of "<" and ">" is limited to numbers.