It seems that when using the sorted set with my own comparator (sorted-set-by), the lookup via 'contains?' function is based only on the part of the items that participate in the ordering:
(contains? (sorted-set [1 :a] [2 :b]) [2 :c]) ;=> false (contains? (sorted-set-by #(< (%1 0) (%2 0)) [1 :a] [2 :b]) [2 :c]) ;=> true The documentation of 'sorted-set-by' says that the _whole_ items are keys: (doc sorted-set-by) ; clojure.core/sorted-set-by ; ([comparator & keys]) ; Returns a new sorted set with supplied keys, using the supplied comparator. ; nil So according to the documentation of 'contains?', it should do lookup based on the whole items, not just their parts used in the comparator: (doc contains?) ; clojure.core/contains? ; ([coll key]) ; Returns true if key is present in the given collection, otherwise ; returns false. Note that for numerically indexed collections like ; vectors and Java arrays, this tests if the numeric key is within the ; range of indexes. 'contains?' operates constant or logarithmic time; ; it will not perform a linear search for a value. See also 'some'. ; nil It's also worth noting that 'sorted-map-by' doesn't behave in this way: (contains? (sorted-map-by #(< (%1 0) (%2 0)) [1 :a] [2 :b]) [2 :c]) ;=> false Can this be a bug? If not, what's the reason behind this behavior? -- Mnicky -- 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