Hm, google groups did not show my first reply to myself for a while, and I thought it had gotten lost in the way, so I sent another post, which can be safely ignored, in case anyone wonders what the difference between the first and the second reply is - there is none, fundamentally.
On Jul 10, 7:54 pm, Eugen Dück <eu...@dueck.org> wrote: > Well, turns out string-like-coll-comparator has a bug: > > x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1 > (vec "n") 2) > (vec "a")) > NullPointerException clojure.lang.AFunction.compare (AFunction.java: > 59) > > It can be fixed though: > > (defn string-like-coll-comparator > [coll1 coll2] > (or (first (drop-while zero? (map compare coll1 coll2))) > (- (count coll1) (count coll2)))) > > Now, is this the way to get the sorting behavior I want or is anyone > aware of something simpler or more performant? > > On Jul 10, 6:09 pm, Eugen Dück <eu...@dueck.org> wrote: > > > > > > > > > Say I have this sorted map, using strings as keys: > > > x=> (sorted-map "ab" 1 "n" 2) > > {"ab" 1, "n" 2} > > > When I do a subseq > > > x=> (subseq (sorted-map "ab" 1 "n" 2) > "aa") > > (["ab" 1] ["n" 2]) > > > I get back both entries. > > > Now if I do the same subseq on the same map, except that I turn all > > strings into character collections, I only get the "ab" entry: > > > x=> (subseq (sorted-map (vec "ab") 1 (vec "n") 2) > (vec "aa")) > > ([[\a \b] 1]) > > > I guess that's fine, the length of collections is probably used first > > and only if it differs would the actual entries be compared. > > > Using my own comparator to simulate the string comparison I can get > > the string-like behavior: > > > (defn string-like-coll-comparator > > [coll1 coll2] > > (first (drop-while zero? (map compare coll1 coll2)))) > > > x=> (subseq (sorted-map-by string-like-coll-comparator (vec "ab") 1 > > (vec "n") 2) > (vec "aa")) > > ([[\a \b] 1] [[\n] 2]) > > > Here's my question - is this the best way to get what I want? -- 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