Thanks Mark, for your response... While I understand what you are saying..
I don't understand as to why the following is working ..
(assoc (pm/priority-map 1 1 2 1) 3 1)
gives
{1 1 2 1 3 1}
Am I not supposed to be using this? will it eventually bite me?
Sunil.
On Fri, Dec 16, 2011 at 3:48 PM, Mark Engelberg <[email protected]>wrote:
> priority-map-by is going to do funky things if your ordering function
> does not obey the trichotomy property (i.e., for all a, b, exactly one
> of a<b, a=b, or a>b holds).
>
> The reason for this is that priority-map internally uses Clojure's
> sorted-map, and Clojure's sorted-map does funky things if the ordering
> function does not obey the trichotomy property.
>
> Let's take a look at the behavior of Clojure's sorted-map with
> something similar to what you are doing:
>
> user=> (def s (sorted-map-by #(> (count %1) (count %2))))
> #'user/s
> user=> (def s1 (assoc s {1 3} 2)))
> #'user/s1
> user=> s1
> {{1 3} 2}
> user=> (assoc s1 {2 3} 3)
> {{1 3} 3}
>
> Look at what happens here. Clojure's sorted-map gets confused because
> your ordering function suggests that {2 3} and {1 3} are considered
> equal, so it just overwrites the value associated with {1 3}.
>
> So since your comparator function screws with sorted-map, it also
> gives bizarre results with priority-map-by.
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en