sorted-map-by value

122 views
Skip to first unread message

Mibu

unread,
Dec 27, 2008, 1:20:45 AM12/27/08
to Clojure
Is there a way to sort a sorted-map-by by value without a letrec?

kwatford

unread,
Dec 27, 2008, 12:50:18 PM12/27/08
to Clojure
Sorted maps sort only on keys, sorry. I was going to suggest using
(sort-by frest foo) to at least get a sequence in the right order, but
it seems like sorting might be broken at the moment? Looks like this
response has turned into a bug report...

user=> (sort [3 1 2])
java.lang.ClassCastException: clojure.core$compare__2931
(NO_SOURCE_FILE:0)

This is most likely because the comparator argument has been tagged as
a Comparator, but the default 'compare' isn't a Comparator.

user=> (sort (comp compare) [3 1 2])
(1 2 3)
user=> (sort-by frest (comp compare) foo)
java.lang.ClassCastException: clojure.core$sort_by__3528$fn__3531
(NO_SOURCE_FILE:0)

The comparison function that sort-by builds isn't a Comparator either.
Drat.

kwatford

unread,
Dec 27, 2008, 1:00:04 PM12/27/08
to Clojure
Oh, nevermind. I hadn't switched my svn over to the Google Code
repository, so I was on 1162... up to 1185 and we're ok.

So yeah.

user=> (sort-by frest {:a 2 :b 3 :c 1})
([:c 1] [:a 2] [:b 3])
Reply all
Reply to author
Forward
0 new messages