On Wed, Dec 2, 2009 at 10:10 AM, Stefan Kamphausen
<[email protected]>wrote:
> OK, the doc of contains? told me that for indexed collection-types it
> will only check, whether the index is within the valid range. So
> maybe:
>
> user> (contains? (list 1 2 3) 1)
> false
>
> At that point I dived into the implementation and found that in
> RT.java checks for the type of collection passed but leaves out
> PersistenList.
>
> I'd like to understand the (probably well-grounded) reason for that.
> As far as I can see PersistentList extends Counted, so the check for
> the index-range should at least be possible. However, I think people
> would expect an equality check in the background, which OTOH would be O
> (N), probably.
It was my impression that in Clojure, lists aren't numerically indexed
collections. That might explain the following:
user=> (contains? '(1 2 3) 1)
false
user=> ('(1 2 3) 1)
java.lang.ClassCastException: clojure.lang.PersistentList (NO_SOURCE_FILE:0)
even though:
user=> (contains? [1 2 3] 1)
true
user=> ([1 2 3] 1)
2
But I might be mistaken, so take this as speculation rather than
explanation.
e
--
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