I don't think I understand what you mean (could you rephrase/example?), I cannot think of a case when I wouldn't want it to throw when I'm passing a non-number (contains? [:a :b :c] :a), I mean, rather than just silently ignoring. It;s not unlike this: => (contains? '(:a :b :c) :a) IllegalArgumentException contains? not supported on type: clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724)
it throws because, it's similarly better than just ignoring it and propagating the bug somewhere else. I don't know about others but, I would prefer if the constraints of a function's definition are violated by ie. devs calling it wrongly (maybe not even anticipating that it could be called wrongly due to it being like generic - perhaps in a manner that you've explained and I didn't quite understand) are enforced and exceptions thrown rather than silently ignoring therefore allowing subtle bugs. In a way, it's already so for String: => (contains? "aaa" 1) true => (contains? "aaa" 3) false => (contains? "aaa" "a") IllegalArgumentException contains? not supported on type: java.lang.String clojure.lang.RT.contains (RT.java:724) => (contains? "aaa" 'a) IllegalArgumentException contains? not supported on type: java.lang.String clojure.lang.RT.contains (RT.java:724) Where it's almost as what I'd want for vector to be, namely: the valid keys numbers, are allowed, but when invalid keys are used ie. symbol or other strings, then exception is thrown; but not so for vectors; Granted that the exception thrown seems to be saying something other than: bad key type for passed collection (or so) but still... => (contains? [1 3 4] 2) true => (contains? [1 3 4] '2) true => (contains? [1 3 4] "2") false So if you were to use this generically on any collection, you'd maybe expect it to throw for vector as it does for string collection. Thanks for replying, Michael. On Fri, Mar 1, 2013 at 6:03 PM, Michael Gardner <gardne...@gmail.com> wrote: > On Feb 28, 2013, at 17:17 , AtKaaZ <atk...@gmail.com> wrote: > > > According to this, can a vector have keys that are not numbers? like :a > , if not, then wouldn't it make more sense that > > (contains? [:a :b :c] :a) would throw ? It's probably just me. > > This is a reasonable point, and one I haven't seen made before. The only > problem I can see with throwing an exception is that one might sometimes > wish to deal with associative containers in a generic fashion, and thus end > up asking a vector if it contains a keyword or a string without doing so > explicitly. In that case you'd not want it to throw an exception any more > than the other associative collection types would. > > -- > -- > 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 > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- Please correct me if I'm wrong or incomplete, even if you think I'll subconsciously hate it. -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.