On 2010 Apr 28, at 7:38 PM, Mark Engelberg wrote:
But I think you're not fully appreciating the complexity of the situation. This is not just about performance, but a question of two different possible semantics for "contains?", which is why it can't *only* be addressed with a protocol.
...
The fundamental problem is that some Clojure data structures have a dual nature. For example, a vector can be thought of as a collection of items, or you can think of it as a mapping from integers to items. A hash map can be thought of as a map, or as a sequence of key-value pairs.
Agreed on the hash map. For vectors, Clojure has already decided that 'seq'ing them ignores their indexes.
The current "contains?" function is really a "contains-key?" function.
Agreed.
There are some people who believe that Clojure would benefit from a variant of "contains?" that views the input as a collection. But how to make this clear? That's why the proposal is for a new function called "seq-contains?". It's not so much a warning of "this thing has performance like a linear search", as much as, "it views your data as a sequence".
Yup. ...
So, if things do move forward with seq-contains? to create a new semantic notion in the clojure core of how to test for containment, I absolutely agree that protocols should be used to make this new notion to continue to have good performance on those sorts of collections for which it is possible to have superior performance than a sequential search.
Perhaps protocols are a touchy subject and there is another mechanism to use, but I haven't yet seen a coherent argument against some mechanism for enhancing performance.
Thanks for the detailed analysis. I guess I had hoped it wouldn't've been necessary. :)
-Doug -- 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