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
<[email protected]> 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 [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> 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 [email protected].
> 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.