The reason why that call doesn't require reflection is that
Collection.unmodifiableSet has no overloaded methods, it only takes a
Set so the compiler doesn't have to disambiguate between different
signatures.

Phillip Lord writes:

> Yes, I checked the code.
>
> (defn set
>   "Returns a set of the distinct elements of coll."
>   {:added "1.0"
>    :static true}
>   [coll] (clojure.lang.PersistentHashSet/create (seq coll)))
>
> And that was my first assumption. But if clojure doesn't know the return
> type, then why does this:
>
> (defn two []
>   (java.util.Collections/unmodifiableSet
>    (set [])))
>
> Not require reflection? Clojure should not know which method to call.
> Unless it is just because unmodifiableSet has an arity of one and it's
> the only arity of one, so it doesn't try to disambiguate.
>
> I guess even if set was type hinted (to IPersistentSet) it would still
> not work since, IPersistentSet is not assignable from java.util.Set.
>
> Phil
>
>
>
> Nicola Mometto <brobro...@gmail.com> writes:
>
>> Actually `set` and a lot of other clojure.core functions are neither
>> inlineable nor have type hints.
>>
>> Phillip Lord writes:
>>
>>> I have a piece of code that looks like this
>>>
>>> (.getOWLEquivalentClassesAxiom
>>>       (owl-data-factory)
>>>       (set classlist)
>>>       (union-annotations classlist))
>>>
>>> The method signature is
>>>
>>> getOWLEquivalentClassesAxiom(Set,Set)
>>>
>>> On runing lein check I get
>>>
>>>
>>> Reflection warning, tawny/owl.clj:2219:6 - call to method
>>> getOWLEquivalentClassesAxiom on
>>> org.semanticweb.owlapi.model.OWLDataFactory can't be resolved (argument
>>> types: unknown, java.util.Set).
>>>
>>> which makes no sense. Surely, the return type of clojure.core/set is
>>> known to be java.util.Set? I have quite a few calls like this in my
>>> code, which is why I don't want to type hint the return of set
>>> individually.
>>>
>>> If I add a function like so:
>>>
>>> (defn ^java.util.Set hset [coll]
>>>   (set coll))
>>>
>>> and call like this:
>>>
>>> (.getOWLEquivalentClassesAxiom
>>>       (owl-data-factory)
>>>       (hset classlist)
>>>       (union-annotations classlist))
>>>
>>> The reflection warning goes away.
>>>
>>>
>>> I've tried to reproduce this with simpler cases, like so:
>>>
>>>
>>> (defn one []
>>>   (java.util.Collections/unmodifiableSet
>>>    (java.util.HashSet.)))
>>>
>>>
>>> (defn two []
>>>   (java.util.Collections/unmodifiableSet
>>>    (set [])))
>>>
>>> But both of these pass lein check just fine. Which suggests that clojure
>>> knows set returns a java.util.Set object.
>>>
>>> Now, given that I can't give a simple test case, I realise that it's
>>> hard for anyone to work out what is happening. But, worse, I don't know
>>> how to debug this at all. So, how I find out what clojure things the
>>> return type of a function is? Or probe any further why this is failing?
>>>
>>> Phil
>>
>> --
>
> --
> Phillip Lord,                           Phone: +44 (0) 191 222 7827
> Lecturer in Bioinformatics,             Email: phillip.l...@newcastle.ac.uk
> School of Computing Science,            
> http://homepages.cs.ncl.ac.uk/phillip.lord
> Room 914 Claremont Tower,               skype: russet_apples
> Newcastle University,                   twitter: phillord
> NE1 7RU

--

-- 
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/d/optout.

Reply via email to