user=> (contains? "abc" 1.5)
true

looks like for that, it's coerced to int

else if(key instanceof Number && (coll instanceof String ||
coll.getClass().isArray())) {
        int n = ((Number) key).intValue();
        return n >= 0 && n < count(coll);
    }
=> (int 1.4)
1
=> (int 1.6)
1
=> (.intValue 1.4)
1
=> (.intValue 1.6)
1



On Fri, Mar 1, 2013 at 9:05 PM, Michael Gardner <gardne...@gmail.com> wrote:

> On Mar 1, 2013, at 13:36 , AtKaaZ <atk...@gmail.com> wrote:
>
> > I don't think I understand what you mean (could you rephrase/example?),
> I cannot think of a case when I wouldn't want it to throw when I'm passing
> a non-number (contains? [:a :b :c] :a), I mean, rather than just silently
> ignoring.
>
> I'm talking about a case where you have one or more associative containers
> of unknown types, and you want to be able to generically ask them whether
> they contain a particular key. E.g.:
>
> (defn has-foo? [c] ;; c is only known to be Associative
>   (contains? c :foo))
>
> Insofar as a vector can be viewed as a kind of associative container, one
> might expect/desire this code to just return false if c happens to be a
> vector. One could see this as a question about the contract promised by the
> Associative interface: is is always OK to ask an Associative container
> whether it contains a given key, or are implementations free to accept only
> certain kinds of keys? I could go either way on that personally, but I
> can't find any docs that support one interpretation or the other.
>
> > It;s not unlike this:
> > => (contains? '(:a :b :c) :a)
> > IllegalArgumentException contains? not supported on type:
> clojure.lang.PersistentList  clojure.lang.RT.contains (RT.java:724)
> >
> > it throws because, it's similarly better than just ignoring it and
> propagating the bug somewhere else.
>
> Different case, because lists aren't Associative.
>
> > In a way, it's already so for String:
> > => (contains? "aaa" 1)
> > true
> > => (contains? "aaa" 3)
> > false
> > => (contains? "aaa" "a")
> > IllegalArgumentException contains? not supported on type:
> java.lang.String  clojure.lang.RT.contains (RT.java:724)
> > => (contains? "aaa" 'a)
> > IllegalArgumentException contains? not supported on type:
> java.lang.String  clojure.lang.RT.contains (RT.java:724)
>
> This one's actually quite surprising to me. I don't know why 'contains?
> throws when given a String and a non-numeric argument, since that's
> inconsistent with its behavior on vectors (and the exception's description
> seems inaccurate, since 'contains? *is* supported on Strings). Even more
> strangely:
>
> user=> (contains? "abc" 1.5)
> true
>
> I have no explanation for this.
>
> --
> --
> 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.
>
>
>


-- 
Please correct me if I'm wrong or incomplete,
even if you think I'll subconsciously hate it.

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


Reply via email to