On Nov 20, 2012, at 10:12 AM, Mark Engelberg wrote:

> Clojure's sorted collections must be provided with a sorting function where 
> items "tie" if and only if they are equal. 
> 
> (sorted-set-by #(compare [(second %) %] [(second %2) %2]) [:a 1] [:b 1] [:c 
> 1]))

Mark, I like the brevity of this way of writing comparison functions with tie 
breakers, and see that it would extend well to multiple sort keys, and 
ascending or descending order on each key can be chosen independently.

My question is perhaps of the 
is-the-number-of-angels-that-can-dance-on-the-head-of-a-pin-finite-or-infinite 
kind.

Does Clojure promise anywhere in its documentation that it compares vectors and 
sequences in lexicographic order?

I know the implementation does in fact do this today, and probably has since 
compare was implemented for vectors, and there is no good reason I know of that 
it might ever change.  For most purposes, I'd say that is good enough to run 
with it and tell the whole world.

The only nagging doubt is relying on undocumented behavior.  I guess my real 
question is: "Would it be good for Clojure to document and promise this 
comparison behavior?"

Andy

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