Re: Wrong documentation of contains?
The keys docstring says it returns a sequence, and that's all you get: it'll do first and next, nothing special about it. The contains? docstring says it won't do a linear search, so that rules out the result of keys. (KeySeq just wraps a seq of entries to return the key field.) What's confusing to me here is that coll? will return true on a sequence. On Wednesday, August 7, 2013 9:15:54 AM UTC-7, puzzler wrote: > > Yes, the discussion about contains? has come up before, but there's a new > aspect to this particular instance of the discussion that most of the posts > seem to be ignoring. > > The original poster specifically pointed out that his sequence was > constructed by calling the `keys` function on a map: > (keys {:a "f" :b 23}) > > He then went on to point out that it doesn't return just a regular, > ordinary lazy sequence, but some sort of special type called a "KeySeq". > > The documentation says that `contains?` looks for whether a given "key" is > present. Probably when the documentation was written, there was some > assumption that by saying it looks for a "key", that makes it obvious it > only works on associative collections. > > But look here, we've got a sequence of keys. We know it is comprised of > keys, and obviously Clojure knows it is a sequence just of keys (because of > the custom type). Therefore, it was reasonable for the poster to think > that `contains?` would work on to determine whether a given key was in the > collection -- it is a collection with keys! > > So I think the new idea here, worthy of discussion, is this: > > How can we reword the doc for `contains?` so that it clearly does not > apply to a sequence of keys? > -- -- 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.
Re: Wrong documentation of contains?
No, it should be more explicit. "If called with a map..." "If called with a vector..." Jonathan On Wed, Aug 7, 2013 at 8:32 PM, Michael Gardner wrote: > Wouldn't changing "collection" to "associative collection" be enough? > Though maybe a note about its behavior on vectors would also be good. > > On Aug 7, 2013, at 11:15 , Mark Engelberg > wrote: > > > Yes, the discussion about contains? has come up before, but there's a > new aspect to this particular instance of the discussion that most of the > posts seem to be ignoring. > > > > The original poster specifically pointed out that his sequence was > constructed by calling the `keys` function on a map: > > (keys {:a "f" :b 23}) > > > > He then went on to point out that it doesn't return just a regular, > ordinary lazy sequence, but some sort of special type called a "KeySeq". > > > > The documentation says that `contains?` looks for whether a given "key" > is present. Probably when the documentation was written, there was some > assumption that by saying it looks for a "key", that makes it obvious it > only works on associative collections. > > > > But look here, we've got a sequence of keys. We know it is comprised of > keys, and obviously Clojure knows it is a sequence just of keys (because of > the custom type). Therefore, it was reasonable for the poster to think > that `contains?` would work on to determine whether a given key was in the > collection -- it is a collection with keys! > > > > So I think the new idea here, worthy of discussion, is this: > > > > How can we reword the doc for `contains?` so that it clearly does not > apply to a sequence of keys? > > > > -- > > -- > > 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. > > > > > > -- > -- > 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. > > > -- -- 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.
Re: Wrong documentation of contains?
Wouldn't changing "collection" to "associative collection" be enough? Though maybe a note about its behavior on vectors would also be good. On Aug 7, 2013, at 11:15 , Mark Engelberg wrote: > Yes, the discussion about contains? has come up before, but there's a new > aspect to this particular instance of the discussion that most of the posts > seem to be ignoring. > > The original poster specifically pointed out that his sequence was > constructed by calling the `keys` function on a map: > (keys {:a "f" :b 23}) > > He then went on to point out that it doesn't return just a regular, ordinary > lazy sequence, but some sort of special type called a "KeySeq". > > The documentation says that `contains?` looks for whether a given "key" is > present. Probably when the documentation was written, there was some > assumption that by saying it looks for a "key", that makes it obvious it only > works on associative collections. > > But look here, we've got a sequence of keys. We know it is comprised of > keys, and obviously Clojure knows it is a sequence just of keys (because of > the custom type). Therefore, it was reasonable for the poster to think that > `contains?` would work on to determine whether a given key was in the > collection -- it is a collection with keys! > > So I think the new idea here, worthy of discussion, is this: > > How can we reword the doc for `contains?` so that it clearly does not apply > to a sequence of keys? > > -- > -- > 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. > > -- -- 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.
Re: Wrong documentation of contains?
Yes, the discussion about contains? has come up before, but there's a new aspect to this particular instance of the discussion that most of the posts seem to be ignoring. The original poster specifically pointed out that his sequence was constructed by calling the `keys` function on a map: (keys {:a "f" :b 23}) He then went on to point out that it doesn't return just a regular, ordinary lazy sequence, but some sort of special type called a "KeySeq". The documentation says that `contains?` looks for whether a given "key" is present. Probably when the documentation was written, there was some assumption that by saying it looks for a "key", that makes it obvious it only works on associative collections. But look here, we've got a sequence of keys. We know it is comprised of keys, and obviously Clojure knows it is a sequence just of keys (because of the custom type). Therefore, it was reasonable for the poster to think that `contains?` would work on to determine whether a given key was in the collection -- it is a collection with keys! So I think the new idea here, worthy of discussion, is this: How can we reword the doc for `contains?` so that it clearly does not apply to a sequence of keys? -- -- 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.
Re: Wrong documentation of contains?
aa the old 'why contains? doesn't work' discussion...even though it's been a while since it last came up on this list, it must be the single most popular questions :) Jim On 07/08/13 12:24, Goldritter wrote: In an program I used the result of keys as an argument for a function which verifies whether an object is in a passed collection or not. The result I got was following Exception: IllegalArgumentException contains? not supported on type: clojure.lang.APersistentMap$KeySeq clojure.lang.RT.contains (RT.java:724) What are the reasons behind this Exception? In the documentation of contains? it is written, that "Returns true if key is present in the given collection, otherwise returns false." The examples on this page (http://clojuredocs.org/clojure_core/clojure.core/contains_q) and the parameter description indicates, that contains? accept any collection as argument. The result of keys is also a collection => (coll? (keys {:a "f" :b 23})) true So is this a bug or is there a reason behind the fact, that contains? does not accept any collection? Or is the documentation wrong and it should nor be a collection as argument but a set or a vector? Because I get the same Exception for a list, but not for a vector. The same for lists, which returns also true for coll?. => (coll? '(1 2 3 4)) true => (contains? '(1 2 3 4) 3) IllegalArgumentException contains? not supported on type: clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) => (contains? [1 2 3 4] 3) true -- -- 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. -- -- 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.
Re: Wrong documentation of contains?
I ran into a similar (in my opinion) issue the other day. I was working a vector and updating a value at a specific index. Ordering and performance were important, so it seemed like a good default choice. (-> [1 2 3] (update-in [1] inc)) Then the code changed a bit, I needed to filter some elements out. I ended up with code similar to what's below (-> (filter odd? [1 2 3]) (update-in [1] inc)) The above code fails, since my vector becomes a lazyseq. I solved the issue in a different way, but I was a bit disappointed that using filter caused me to have to move away from updating at an index. On Wed, Aug 7, 2013 at 9:45 AM, Jay Fields wrote: > that's kind of my point, you wouldn't use contains? with a list 99.99% of > the time (you probably want some), so if the perf is terrible while you're > figuring out that you want some, it doesn't matter. > > > On Wed, Aug 7, 2013 at 9:39 AM, Jeremy Heiler wrote: > >> On August 7, 2013 at 9:02:51 AM, Tassilo Horn (t...@gnu.org) wrote: >> >> Jay Fields writes: >> >> > For a list, it seems like converting the list to a vectoc (via vec) >> > would be a reasonable solution, though I'm sure there's some side >> > effect that I haven't considered. Perf would be impacted, but this >> > doesn't seem like the kind of thing you'd want to do anyway, so having >> > poor perf wouldn't be the end of the world. At least it wouldn't >> > exception out. >> >> IMHO, it would be bad if converting lists (and seqs?) to vectors would >> be done under the hoods. There are high chances that you accidentally >> pass a seq/list to `contains?` and then suffer from worse performance >> without actually noticing. E.g. you do something like >> >> (contains? (map fuddle blabla) 3) ;; has at least 4 items >> >> where you actually wanted to do >> >> (contains? (mapv fuddle blabla) 3) ;; has at least 4 items >> >> I'm not sure any conversion should take place. The confusion with vectors >> is that (contains? [1 2 3 4] 3) returns true because there are four >> elements, not because 3 is present. So by returning false, false >> assumptions are being validated in various cases. >> >> >> > -- -- 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.
Re: Wrong documentation of contains?
On Aug 7, 2013, at 8:22 AM, Jay Fields wrote: > contains? is possibly poorly named, contains-key? would probably have avoided > this entire issue. I'd put it more strongly -- contains? is definitely poorly named, inviting the assumption that it can be used where you really want "some" with a set as the predicate. I've made the mistake myself and so have my students, many times. So now I single this out for a special warning in my classes, saying that the name is misleading so beware. I guess it's too late to do anything about it now, but I think this name was clearly a mistake. -Lee -- -- 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.
Re: Wrong documentation of contains?
Jay Fields writes: > For a list, it seems like converting the list to a vectoc (via vec) > would be a reasonable solution, though I'm sure there's some side > effect that I haven't considered. Perf would be impacted, but this > doesn't seem like the kind of thing you'd want to do anyway, so having > poor perf wouldn't be the end of the world. At least it wouldn't > exception out. IMHO, it would be bad if converting lists (and seqs?) to vectors would be done under the hoods. There are high chances that you accidentally pass a seq/list to `contains?` and then suffer from worse performance without actually noticing. E.g. you do something like (contains? (map fuddle blabla) 3) ;; has at least 4 items where you actually wanted to do (contains? (mapv fuddle blabla) 3) ;; has at least 4 items Bye, Tassilo -- -- 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.
Re: Wrong documentation of contains?
contains? is possibly poorly named, contains-key? would probably have avoided this entire issue. That said, I'd like to see contains? return false for things where it doesn't make sense, longs, keywords, etc. For a list, it seems like converting the list to a vectoc (via vec) would be a reasonable solution, though I'm sure there's some side effect that I haven't considered. Perf would be impacted, but this doesn't seem like the kind of thing you'd want to do anyway, so having poor perf wouldn't be the end of the world. At least it wouldn't exception out. On Wed, Aug 7, 2013 at 8:14 AM, Jonathan Fischer Friberg < odysso...@gmail.com> wrote: > That's only obvious if you already know how it works. > > Jonathan > > > On Wed, Aug 7, 2013 at 2:13 PM, Karsten Schmidt wrote: > >> The fact, that the docs refer to checking if a "key" is present in the >> collection, should make it obvious which types are supported, no? Only >> vectors, maps and sets have keys. Lists and seqs do not. Of course it never >> hurts to be more explicit about it... >> On 7 Aug 2013 12:49, "Marcus Lindner" < >> marcus.goldritter.lind...@gmail.com> wrote: >> >>> Thanks. >>> >>> But the problem is, that this is not mentioned in the documentation of >>> contains? I found so far :(. >>> I had such a problem a long time ago and remember now which type of >>> "collection" can be used with contains?. But after a time I will forget >>> this again and will refer to the documentation. (And when I get the >>> Exception I remember again.) >>> >>> And I think this question arise also more frequently. >>> >>> But then my assumption that the documentation of contains? is misleading >>> is true. Is it possible to update the documentation for the next version? >>> >>> >>> >>> >>> >>> >>> 2013/8/7 Baishampayan Ghose >>> Hi, `contains?` only works with associative data-structures like maps & vectors. If you want to find out if a sequence contains a specific object then you need to use `some` paired with a set as a predicate. For example: (some #{3} '(1 2 3 4)) Hope this helps. ~BG On Wed, Aug 7, 2013 at 4:54 PM, Goldritter wrote: > In an program I used the result of keys as an argument for a function which > verifies whether an object is in a passed collection or not. > The result I got was following Exception: > IllegalArgumentException contains? not supported on type: > clojure.lang.APersistentMap$KeySeq clojure.lang.RT.contains (RT.java:724) > > What are the reasons behind this Exception? > > In the documentation of contains? it is written, that > "Returns true if key is present in the given collection, otherwise returns > false." > The examples on this page > (http://clojuredocs.org/clojure_core/clojure.core/contains_q) and the > parameter description indicates, that contains? accept any collection as > argument. > > The result of keys is also a collection > => (coll? (keys {:a "f" :b 23})) > true > > So is this a bug or is there a reason behind the fact, that contains? does > not accept any collection? > Or is the documentation wrong and it should nor be a collection as argument > but a set or a vector? > > Because I get the same Exception for a list, but not for a vector. > The same for lists, which returns also true for coll?. > => (coll? '(1 2 3 4)) > true > > => (contains? '(1 2 3 4) 3) > IllegalArgumentException contains? not supported on type: > clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) > > => (contains? [1 2 3 4] 3) > true > > -- > -- > 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. > > -- Baishampayan Ghose b.ghose at gmail.com -- -- 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 unsubs
Re: Wrong documentation of contains?
That's only obvious if you already know how it works. Jonathan On Wed, Aug 7, 2013 at 2:13 PM, Karsten Schmidt wrote: > The fact, that the docs refer to checking if a "key" is present in the > collection, should make it obvious which types are supported, no? Only > vectors, maps and sets have keys. Lists and seqs do not. Of course it never > hurts to be more explicit about it... > On 7 Aug 2013 12:49, "Marcus Lindner" > wrote: > >> Thanks. >> >> But the problem is, that this is not mentioned in the documentation of >> contains? I found so far :(. >> I had such a problem a long time ago and remember now which type of >> "collection" can be used with contains?. But after a time I will forget >> this again and will refer to the documentation. (And when I get the >> Exception I remember again.) >> >> And I think this question arise also more frequently. >> >> But then my assumption that the documentation of contains? is misleading >> is true. Is it possible to update the documentation for the next version? >> >> >> >> >> >> >> 2013/8/7 Baishampayan Ghose >> >>> Hi, >>> >>> `contains?` only works with associative data-structures like maps & >>> vectors. If you want to find out if a sequence contains a specific >>> object then you need to use `some` paired with a set as a predicate. >>> >>> For example: >>> >>> (some #{3} '(1 2 3 4)) >>> >>> Hope this helps. >>> >>> ~BG >>> >>> >>> On Wed, Aug 7, 2013 at 4:54 PM, Goldritter >>> wrote: >>> > In an program I used the result of keys as an argument for a function >>> which >>> > verifies whether an object is in a passed collection or not. >>> > The result I got was following Exception: >>> > IllegalArgumentException contains? not supported on type: >>> > clojure.lang.APersistentMap$KeySeq clojure.lang.RT.contains >>> (RT.java:724) >>> > >>> > What are the reasons behind this Exception? >>> > >>> > In the documentation of contains? it is written, that >>> > "Returns true if key is present in the given collection, otherwise >>> returns >>> > false." >>> > The examples on this page >>> > (http://clojuredocs.org/clojure_core/clojure.core/contains_q) and the >>> > parameter description indicates, that contains? accept any collection >>> as >>> > argument. >>> > >>> > The result of keys is also a collection >>> > => (coll? (keys {:a "f" :b 23})) >>> > true >>> > >>> > So is this a bug or is there a reason behind the fact, that contains? >>> does >>> > not accept any collection? >>> > Or is the documentation wrong and it should nor be a collection as >>> argument >>> > but a set or a vector? >>> > >>> > Because I get the same Exception for a list, but not for a vector. >>> > The same for lists, which returns also true for coll?. >>> > => (coll? '(1 2 3 4)) >>> > true >>> > >>> > => (contains? '(1 2 3 4) 3) >>> > IllegalArgumentException contains? not supported on type: >>> > clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) >>> > >>> > => (contains? [1 2 3 4] 3) >>> > true >>> > >>> > -- >>> > -- >>> > 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. >>> > >>> > >>> >>> >>> >>> -- >>> Baishampayan Ghose >>> b.ghose at gmail.com >>> >>> -- >>> -- >>> 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. >>> >>> >>> >> -- >> -- >> 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.
Re: Wrong documentation of contains?
The fact, that the docs refer to checking if a "key" is present in the collection, should make it obvious which types are supported, no? Only vectors, maps and sets have keys. Lists and seqs do not. Of course it never hurts to be more explicit about it... On 7 Aug 2013 12:49, "Marcus Lindner" wrote: > Thanks. > > But the problem is, that this is not mentioned in the documentation of > contains? I found so far :(. > I had such a problem a long time ago and remember now which type of > "collection" can be used with contains?. But after a time I will forget > this again and will refer to the documentation. (And when I get the > Exception I remember again.) > > And I think this question arise also more frequently. > > But then my assumption that the documentation of contains? is misleading > is true. Is it possible to update the documentation for the next version? > > > > > > > 2013/8/7 Baishampayan Ghose > >> Hi, >> >> `contains?` only works with associative data-structures like maps & >> vectors. If you want to find out if a sequence contains a specific >> object then you need to use `some` paired with a set as a predicate. >> >> For example: >> >> (some #{3} '(1 2 3 4)) >> >> Hope this helps. >> >> ~BG >> >> >> On Wed, Aug 7, 2013 at 4:54 PM, Goldritter >> wrote: >> > In an program I used the result of keys as an argument for a function >> which >> > verifies whether an object is in a passed collection or not. >> > The result I got was following Exception: >> > IllegalArgumentException contains? not supported on type: >> > clojure.lang.APersistentMap$KeySeq clojure.lang.RT.contains >> (RT.java:724) >> > >> > What are the reasons behind this Exception? >> > >> > In the documentation of contains? it is written, that >> > "Returns true if key is present in the given collection, otherwise >> returns >> > false." >> > The examples on this page >> > (http://clojuredocs.org/clojure_core/clojure.core/contains_q) and the >> > parameter description indicates, that contains? accept any collection as >> > argument. >> > >> > The result of keys is also a collection >> > => (coll? (keys {:a "f" :b 23})) >> > true >> > >> > So is this a bug or is there a reason behind the fact, that contains? >> does >> > not accept any collection? >> > Or is the documentation wrong and it should nor be a collection as >> argument >> > but a set or a vector? >> > >> > Because I get the same Exception for a list, but not for a vector. >> > The same for lists, which returns also true for coll?. >> > => (coll? '(1 2 3 4)) >> > true >> > >> > => (contains? '(1 2 3 4) 3) >> > IllegalArgumentException contains? not supported on type: >> > clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) >> > >> > => (contains? [1 2 3 4] 3) >> > true >> > >> > -- >> > -- >> > 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. >> > >> > >> >> >> >> -- >> Baishampayan Ghose >> b.ghose at gmail.com >> >> -- >> -- >> 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. >> >> >> > -- > -- > 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,
Re: Wrong documentation of contains?
Marcus Lindner writes: > But the problem is, that this is not mentioned in the documentation of > contains? I found so far :(. Well, it kind of is: Only associative data structures (maps, sets, records, vectors) have keys, lists and seqs (such as APersistentMap$KeySeq) don't. I guess the confusion comes that people are used that myMap.keySet() returns a set (which is an associative data structure) whereas (keys my-map) returns a seq, not a set. Bye, Tassilo -- -- 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.
Re: Wrong documentation of contains?
Thanks. But the problem is, that this is not mentioned in the documentation of contains? I found so far :(. I had such a problem a long time ago and remember now which type of "collection" can be used with contains?. But after a time I will forget this again and will refer to the documentation. (And when I get the Exception I remember again.) And I think this question arise also more frequently. But then my assumption that the documentation of contains? is misleading is true. Is it possible to update the documentation for the next version? 2013/8/7 Baishampayan Ghose > Hi, > > `contains?` only works with associative data-structures like maps & > vectors. If you want to find out if a sequence contains a specific > object then you need to use `some` paired with a set as a predicate. > > For example: > > (some #{3} '(1 2 3 4)) > > Hope this helps. > > ~BG > > > On Wed, Aug 7, 2013 at 4:54 PM, Goldritter > wrote: > > In an program I used the result of keys as an argument for a function > which > > verifies whether an object is in a passed collection or not. > > The result I got was following Exception: > > IllegalArgumentException contains? not supported on type: > > clojure.lang.APersistentMap$KeySeq clojure.lang.RT.contains > (RT.java:724) > > > > What are the reasons behind this Exception? > > > > In the documentation of contains? it is written, that > > "Returns true if key is present in the given collection, otherwise > returns > > false." > > The examples on this page > > (http://clojuredocs.org/clojure_core/clojure.core/contains_q) and the > > parameter description indicates, that contains? accept any collection as > > argument. > > > > The result of keys is also a collection > > => (coll? (keys {:a "f" :b 23})) > > true > > > > So is this a bug or is there a reason behind the fact, that contains? > does > > not accept any collection? > > Or is the documentation wrong and it should nor be a collection as > argument > > but a set or a vector? > > > > Because I get the same Exception for a list, but not for a vector. > > The same for lists, which returns also true for coll?. > > => (coll? '(1 2 3 4)) > > true > > > > => (contains? '(1 2 3 4) 3) > > IllegalArgumentException contains? not supported on type: > > clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) > > > > => (contains? [1 2 3 4] 3) > > true > > > > -- > > -- > > 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. > > > > > > > > -- > Baishampayan Ghose > b.ghose at gmail.com > > -- > -- > 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. > > > -- -- 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.
Re: Wrong documentation of contains?
Hi, `contains?` only works with associative data-structures like maps & vectors. If you want to find out if a sequence contains a specific object then you need to use `some` paired with a set as a predicate. For example: (some #{3} '(1 2 3 4)) Hope this helps. ~BG On Wed, Aug 7, 2013 at 4:54 PM, Goldritter wrote: > In an program I used the result of keys as an argument for a function which > verifies whether an object is in a passed collection or not. > The result I got was following Exception: > IllegalArgumentException contains? not supported on type: > clojure.lang.APersistentMap$KeySeq clojure.lang.RT.contains (RT.java:724) > > What are the reasons behind this Exception? > > In the documentation of contains? it is written, that > "Returns true if key is present in the given collection, otherwise returns > false." > The examples on this page > (http://clojuredocs.org/clojure_core/clojure.core/contains_q) and the > parameter description indicates, that contains? accept any collection as > argument. > > The result of keys is also a collection > => (coll? (keys {:a "f" :b 23})) > true > > So is this a bug or is there a reason behind the fact, that contains? does > not accept any collection? > Or is the documentation wrong and it should nor be a collection as argument > but a set or a vector? > > Because I get the same Exception for a list, but not for a vector. > The same for lists, which returns also true for coll?. > => (coll? '(1 2 3 4)) > true > > => (contains? '(1 2 3 4) 3) > IllegalArgumentException contains? not supported on type: > clojure.lang.PersistentList clojure.lang.RT.contains (RT.java:724) > > => (contains? [1 2 3 4] 3) > true > > -- > -- > 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. > > -- Baishampayan Ghose b.ghose at gmail.com -- -- 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.