It doesn't seem confusing to me. You are taking complete control of
the set's local notion of ordering and equality. This is what I'd
expect.

Here's an example. First, a handy little function from Haskell:

(defn on [key f]
  #(apply f (map key %&)))

Then:

user> (sorted-set-by (on :id compare)
   {:id 42 :name "Per" :age 28}
   {:id 0 :name "Methuselah" :age 9000}
   {:id 42 :name "Rep" :age 82})

#{{:id 0, :name "Methuselah", :age 9000} {:id 42, :name "Per", :age 28}}

That is, it's eliminating entries with duplicate primary keys in favor
of earlier occurrences.

-Per

On Fri, Apr 16, 2010 at 9:38 PM, Sean Devlin <francoisdev...@gmail.com> wrote:
> Here's the source for sorted-set-by:
>
> (defn sorted-set-by
>  "Returns a new sorted set with supplied keys, using the supplied
> comparator."
>  ([comparator & keys]
>   (clojure.lang.PersistentTreeSet/create comparator keys)))
>
> This is because your comparator is saying that everything is equal.
> PersistentTreeSet delegates a lot of work to PersistentTreeMap, so the
> object is happily replacing every element when the comparator is zero.
>
> I'm not sure if this is a bug or the intended behavior...  I'm leaning
> toward the latter, even though it's confusing.
>
> Sean
>
> On Apr 16, 8:25 am, Razvan <gigi.clan...@gmail.com> wrote:
>> Hi,
>>
>> Is this the intended behavior?
>>
>> (sorted-set-by (constantly 0) 1 2 3 4) returns #{1}.
>>
>> I would expect the set to contain all the elements, and the comparator
>> to only affect sort order.
>>
>> Razvan
>>
>> --
>> 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 
>> athttp://groups.google.com/group/clojure?hl=en
>
> --
> 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

-- 
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

Reply via email to