> Explain me this, please:
>
> user=> (def x (cons 'a nil))
> #'user/x
> user=> x
> (a)
> user=> (contains? x 'a)
> false
> user=>

contains? checks whether the collection contains the *key*, not the
value. So for example the list [:a :b] contains keys 0 and 1, but not
2 or :a:

user=> (contains? [:a :b] 0)
true
user=> (contains? [:a :b] 1)
true
user=> (contains? [:a :b] 2)
false
user=> (contains? [:a :b] :a)
false

That said, it was not obvious from (doc contains?) to me what the
semantics were for operating on lists. Checking PersistentList, it
seems contains() always returns false - which makes sense if you
consider that lists are not functions of indexes (while vectors and
java arrays are).

-- 
/ Peter Schuller

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

Reply via email to