On Apr 30, 2010, at 6:33 AM, Rich Hickey wrote:

> Would contains-val? be fast for sets?  As a user of sets, I consider them 
> collections of values, and I absolutely would reach for contains-val? in any 
> library that had it, for use with sets. If so, and I used contains-val?, and 
> I moved code from using sets to maps (happens frequently), or vectors (also 
> happens) my perf would suddenly stink. If not fast on sets, why not? The 
> reason isn't supported by the name.

You should understand the performance characteristics of the data structures 
you employ, under whatever operations you subject them to. Being surprised when 
your code that looks stuff up by value slows down when you switch from sets to 
something else doesn't strike me as reasonable.

> 'contains?' and 'get' abstract over fast lookup. They are polymorphic on the 
> collection type and on the nature of the looked-up thing. For maps the 
> looked-up thing is a key, for sets: a value, for vectors, strings and arrays: 
> an index.  Calling it contains-key? doesn't make them the same, nor add any 
> value.

The objects in a set are both keys and values, and an index *is* a key. The 
documentation for get and contains? implies this, as others have noted.

> Renaming contains? is not on the table.

I hope you will reconsider this, if not now then at some point in the future.

> For people that understand its relationship with get, it makes perfect sense 
> (and I don't think I'm the only one :).

As would contains-key?, I think.

> And there is a lot of client code.

No need to rename immediately; alias and deprecate.

> And no one has come up with a better name that doesn't include caveats.

I don't see any caveats for contains-key? other than the one addressed above.

> I do understand that this use of the word differs from that used in e.g., 
> Java. But I'll make the same argument to Java devs that I do to the Lispers, 
> who have seen many more of their prized words repurposed in Clojure (assoc, 
> loop, do et al):
> 
>    The words can't mean the same thing forever without trapping us in the 
> same semantics forever, and there are only so many good words.
> 
> Everyone has to realize that this level of polymorphism in Clojure is 
> unusual. I haven't seen a library with equivalents to get and contains?. 
> Heck, in Java, Maps aren't even collections! So, should we adopt their 
> nomenclature because it is familiar?

contains? isn't a bad name because it's used differently in Java. It's bad 
because it's ambiguous, and because there's a much clearer name available.

> I agree that contains?'s behavior on vectors is confusing for newcomers. 
> That's not a reason for it to be different.

I disagree.

> The only options for right now are:
> 
> A) I remove seq-contains?
> B) I rename seq-contains?

Something involving the word 'scan', perhaps?

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