Thanks for explanation, all!

Frantisek

On 20 Ún, 20:57, Jason Wolfe <jawo...@berkeley.edu> wrote:
> It probably does an "identical?" call on a pair before calling
> compare, for efficiency.  In other words, it may "work" on non-
> comparable types, but only when passed n instances of the exact same
> object:
>
> user> (sorted-set '(1) '(1))
> ; Exception
>
> user> (let [x '(1)] (sorted-set x x))
> #{(1)}
>
> This is almost certainly not documented behavior and should not be
> relied upon.
>
> Cheers,
> Jason
>
> On Feb 20, 11:42 am, Frantisek Sodomka <fsodo...@gmail.com> wrote:
>
> > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to