On Jan 29, 10:41 pm, Paul Barry <pauljbar...@gmail.com> wrote:
> This is actually the point of this whole debate.  You would assume that
> contains? works like java.util.Collection.contains, but instead it means
> something completely semantically different.
> user=> (.contains [4 5 6] 4)
> true
> user=> (contains? [4 5 6] 4)
> false
>
> Even worse, you do this and think it works:
>
> user=> (.contains [1 2 3] 1)
> true
> user=> (contains? [1 2 3] 1)
> true
>
> This isn't about having a method that does the same thing as .contains or
> includes? from contrib, it's about naming this method, the one that tells
> you if the associative thing has a particular key, something less confusing.
>
> This is just one of those things that a lot of people new to Clojure will
> learn the hard way at some point.  And they'll probably send another email
> to the mailing list and we'll have the debate all over again.  Once Clojure
> goes 1.0, this problem is permanent, so we have until then to convince Rich
> to rename this method to contains-key? (which mimics the name in the
> java.util.Map interface) or has-key? (for something shorter).
>
> Maybe I'll setuphttp://pleaserenamecontainsrich.com:)
>

Sequential lookup is not an important operation. Clojure includes sets
and maps, and if you are going to be looking things up you should be
using them. contains? maps to java.util.Set.contains. The fact that
java.util.Collection also has contains is, IMO, a mistake, as you
really can't write code to an interface with dramatically varying
performance characteristics.

So, lookups in sets and maps take priority and get the best name -
contains?

People write naive programs that do linear lookups with contains() in
other languages, and get correspondingly bad n-squared performance -
that's not an argument for encouraging that in Clojure. If they get an
explanation of why it's a bad idea, and how to use sets and maps,
that's fine.

If you want a linear lookup function, it's going to have a big warning-
sign name, like linear-lookup.

I'm not persuaded in any way to rename contains?

Rich

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