On Apr 30, 2010, at 14:33 , Rich Hickey wrote: > > '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.
I think if contains? and get are in 'the same group' the names should reflect that, readability of code and expressive names are very important if someone reads (contains? [1 2 3] 3) he will assume it to be true and I bet about 90% of the people using clojure will make this miss assumption since people think english first and clojure second. if I they read (contains-key? [1 2 3] 3) they will think twice, 'key on a vec, oh index yes so it is false' if they read (contains-val? [1 2 3] 3) they will also think twice, 'val on a vec, ah yes means if it include that value'. > In Clojure, 'contains?' is about 'get' succeeding. Nothing more or less. It > is not a rummager. > > (if (contains? coll x) > (get coll x) > (plan-b)) > Then ow about can-get? since contains does not actually look of the passed thing contains anything it is just looking of you can get stuff from it, you sayed it yourself: (if (can-get? coll x) (get coll x) (plan-c-as-c4) > Renaming contains? is not on the table. For people that understand its > relationship with get, it makes perfect sense (and I don't think I'm the only > one :). And there is a lot of client code. And no one has come up with a > better name that doesn't include caveats. contains? is internally consistent, > is unfamiliar. Sorry I disagree here, I now understand the relationship with get and it makes even less sense to me then before -.- if it has to do with get contains? is a very very bad name. Think about translating stuff to real world examples, if I ask you 'does your bag contains x' I don't want to know if the bag has more then x items I want to know if x is in there. Whenever we use contains we talk about the content in the real world. Even if we use it with indices as in 'does this book contains page 42' we clarify that we are talking about the index by adding 'page' in there, if we ask 'does this book contains 42' people will likely start to look if there is a 42 in the book, and if it is the hitchhikers guide to the galaxy the answer is yes, otherwise most likely no. So pretty pretty please reconsider the decision about renaming contains > 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. But choosing a misleading name just for the sake of chaining the semantics is not the way to go! > 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? Trust me I don't care how java uses contains? that isn't an argument I would raise, but I care about how the human mind, uses contains, and currently it is different to the usage in clojure. > I agree that contains?'s behavior on vectors is confusing for newcomers. > That's not a reason for it to be different. And that people need a way to do > that rummaging job. They of course can, with 'some'. But I also agree that > 'some', being a higher-order function, would not necessarily be the tool > newcomers would consider for the job of rummaging for a value. Perhaps it's a > good first lesson, as they are not going to find filter-val etc either. I am pretty certain the behaviour of contains? is confusing even to somewhat versed people, just that at some point people resign and put back comen sense and let clojure do it's thing with contains?, but this isn't a good thing in my eyes :(. Also 'does this collection contains the value X' is a quite common idiom isn't it? so why force a higher order function onto that? > So, I pulled in 'includes?' from contrib and renamed it seq-contains? > > The only options for right now are: > > A) I remove seq-contains? > B) I rename seq-contains? :.( Regards a sad, Heinz -- 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