On Jun 22, 2009, at 1:23 AM, kkw wrote:
I had some fortune with the sorted-by function: 1:11 user=> (sort-by (fn [e] (second e)) [[1 99] [3 4] [5 6] [7 8]]) ([3 4] [5 6] [7 8] [1 99])
You were using the form of sort-by that accepts a "keyfn", not the one where you also provide a comparator.
so I thought I'd have a go with sorted-map-by also:
1:13 user=> (doc sorted-map-by)
-------------------------
clojure.core/sorted-map-by
([comparator & keyvals])
keyval => key val
Returns a new sorted map with supplied mappings, using the supplied
comparator.
1:14 user=> (sorted-map-by (fn [c] c) 1 2)
{1 2}
No comparisons were necessary, so your comparator function wasn't called.
1:16 user=> (sorted-map-by (fn [c] c) 1 2 3 4) java.lang.RuntimeException: java.lang.IllegalArgumentException: Wrong number of args passed to: user$eval--85$fn (repl-1:16)
sorted-map-by called your comparator, but comparators take two arguments and your function only accepts one.
--Steve
smime.p7s
Description: S/MIME cryptographic signature
