It looks that it is more complicated than that: user=> (sorted-set () ()) #{()} user=> (sorted-set {} {}) #{{}} user=> (sorted-set #{} #{}) #{#{}}
Frantisek On 20 Ún, 20:33, Vincent Foley <vfo...@gmail.com> wrote: > I'm pretty sure that sorted-set works only with values that are > instances of a class that implements Comparable. > > user=> (instance? Comparable []) > true > user=> (instance? Comparable {}) > false > user=> (instance? Comparable ()) > false > user=> > > On Feb 20, 2:21 pm, Frantisek Sodomka <fsodo...@gmail.com> wrote: > > > sorted-set works for vectors, but doesn't work for lists, maps and > > sets: > > user=> (sorted-set [1 4]) > > #{[1 4]} > > user=> (sorted-set [1 4] [1 4]) > > #{[1 4]} > > user=> (sorted-set [4 1] [1 4]) > > #{[1 4] [4 1]} > > > user=> (sorted-set '(1 4)) > > #{(1 4)} > > user=> (sorted-set '(1 4) '(1 4)) > > java.lang.ClassCastException: clojure.lang.PersistentList cannot be > > cast to java.lang.Comparable (NO_SOURCE_FILE:0) > > > user=> (sorted-set {:a 1 :b 2}) > > #{{:a 1, :b 2}} > > user=> (sorted-set {:a 1 :b 2} {:a 1 :b 2}) > > java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot > > be cast to java.lang.Comparable (NO_SOURCE_FILE:0) > > > user=> (sorted-set #{1 2}) > > #{#{1 2}} > > user=> (sorted-set #{1 2} #{1 2}) > > java.lang.ClassCastException: clojure.lang.PersistentHashSet cannot be > > cast to java.lang.Comparable > > (NO_SOURCE_FILE:0) > > > --- > > How does sorted-set know which value is bigger or smaller? Could this > > functionality be exported? > > user=> (sorted-set [4 3] [2 1]) > > #{[2 1] [4 3]} > > user=> (> [4 3] [2 1]) > > java.lang.ClassCastException: clojure.lang.LazilyPersistentVector > > cannot be cast to java.lang.Number (NO_SOURCE_FILE:0) > > user=> (= [4 3] [2 1]) > > false > > > user=> (> "xyz" "abc") > > java.lang.ClassCastException: java.lang.String cannot be cast to > > java.lang.Number (NO_SOURCE_FILE:0) > > > Thank you, Frantisek --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---