On Tue, Nov 20, 2012 at 11:08 AM, Andy Fingerhut
<andy.finger...@gmail.com>wrote:

>
> Then my question is still: "Would it be good for Clojure to document and
> promise this comparison behavior?"
>
> If not for all cases, at least for equal-length vectors being compared
> lexicographically?
>
>
I frequently rely on Clojure's behavior that equal-length vectors are
compared lexicographically, so I certainly hope that this is an implicit
promise, but I don't know that I've seen it documented anywhere.

I've thought about how it would be nice to have a library with several
useful comparators for complex objects.  For example:

1. True lexicographic comparison for all sequences (both vectors and lists).
Right now, lists can't be compared.  Vectors compare by length first.

2. Something that can compare all possible Clojure objects in an arbitrary
but consistent way.
There are a lot of times where you just want distinct objects to have some
sort of tiebreaker so that sorting will work, but you don't really care
what order tied items end up in.  For example, I may want to create a
sorted collection out of [[1 :a] [2 :b] [1 "c"]] in a way that guarantees
that the 1 entries are before the 2 entry, but I don't really care about
the exact order of the 1 entries.  Several other languages handle this by
ensuring that all objects can be compared, I think Python is an example of
this.  This way the trick I showed of (sort-by #(compare
[(attribute-I-care-about %) %] [(attribute-I-care-about %2) %2)]) ...) will
always work.


Haven't gotten around to implementing said library, although I probably
should since I seem to end up re-implementing bits and pieces of these
ideas in my own code all the time.

-- 
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

Reply via email to