Hi Steve, I find the -1, 0, 1 result more useful, but am also wary it hides some useful information. My preference would be to have the doc-string changed to what you proposed and keep the neg/pos behaviour of .compareTo in place. To get -1, 0, 1 requires a 'sign' operator which is handy to have as a separate function - might be a candidate for contrib?
(defn sign "Returns 1 if x is positive, -1 if x is negative, else 0" [x] (cond (pos? x) 1, (neg? x) -1, :else 0)) user=> ((comp sign compare) \a \g) -1 hmmm bit verbose, but lets the user choose if they want compareTo or -1, 0, 1 Regards, Tim. On Sep 9, 7:35 am, "Stephen C. Gilardi" <squee...@mac.com> wrote: > On Sep 8, 2009, at 2:14 AM, Timothy Pratley wrote: > > > According to the docstring compare returns -1, 0 or 1: > > user=> (compare \b \g) > > -5 > > We could fix the doc along the lines of: > > "Comparator. Returns a negative number, zero, or a positive number > when x is logically 'less than', 'equal to', or 'greater than' y. > Same as Java x.compareTo(y) except it also works for nil, and compares > numbers and collections in a type-independent manner. x must implement > Comparable" > > or fix the implementation to conform to the current doc. > > My current thought is that we should fix the implementation and make a > minor mod to the doc to replace "Same as" with something like "Works > like" because compareTo only guarantees the sign of the return value. > > Other thoughts? > > --Steve > > smime.p7s > 3KViewDownload --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---