Thank you very much to all for comprehensive explanations.
As newcomer to Clojure dare to remark that this is not very consistent
semantics of "contains" :)

On 25 июн, 21:25, ataggart <alex.tagg...@gmail.com> wrote:
> My sense from reading Rich's writing on the subject is that 'contains?
> was named with the use of sets in mind.  There is also a pairing logic
> involved whereby if 'contains? returns true, the the value returned by
> 'get is valid (this covers cases in maps where the value actually is
> nil).
>
> As Meikel indicated, this is a well-worn path of discussion and isn't
> going to change.
>
> On Jun 25, 5:15 am, Peter Schuller <peter.schul...@infidyne.com>
> wrote:
>
>
>
> > > 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