Clojure sort: is it specified to be stable for all targets?

127 views
Skip to first unread message

Daniel Pittman

unread,
Sep 12, 2011, 1:06:41 AM9/12/11
to clo...@googlegroups.com
G'day.

The API documentation for clojure doesn't specify if the sort method
is stable, unstable, or "implementation defined".

Java defines sort to be stable, but Clojure also has two other
targets, and I can't tell if I am safe making the assumption that the
stable behaviour will carry over to them, or if they will just have
whatever the implementor decided.

Daniel
--
♲ Made with 100 percent post-consumer electrons

Stuart Sierra

unread,
Sep 12, 2011, 7:48:42 PM9/12/11
to clo...@googlegroups.com
In general, if it's not specified in the doc string, then it's not a promise. That said, the implementation of `sort` in Clojure on the JVM uses java.util.Arrays#sort, which is specified to be stable.

I would generally expect a language built-in `sort` routine to be stable, so take that for what it's worth.

-Stuart Sierra
clojure.com
Reply all
Reply to author
Forward
0 new messages