Hi Konrad!

Konrad Hinsen a écrit :
> Given the definitions:
>
> (defmulti foo class)
> (defmethod foo clojure.lang.IPersistentCollection [_] :a-collection)
> (defmethod foo clojure.lang.IPersistentVector [_] :a-vector)
>
> one obtains the following results:
>
> (foo [1 2 3])  -> :a-vector
> (foo #{1 2 3}) -> :a-collection
>
> This looks perfectly logical from an OO point of view, but I cannot  
> find anything in the documentation (http://clojure.org/multimethods)  
> that actually promises that the vector implementation of foo takes  
> precedence over the generic collection version if the argument is a  
> vector. Can I rely on that or should I add
>
> (prefer-method foo clojure.lang.IPersistentVector  
> clojure.lang.IPersistentCollection)
>
> explicitly?
>   

user=> (ancestors clojure.lang.IPersistentVector)
#{clojure.lang.Sequential clojure.lang.Associative 
clojure.lang.IPersistentCollection clojure.lang.Reversible 
clojure.lang.IPersistentStack}

Hence clojure.lang.IPersistentVector clearly dominates 
clojure.lang.IPersistentCollection: there's no need for prefer-method.
"prefer-method <http://clojure.org/api#prefer-method> is used for 
disambiguating in case of multiple matches where neither dominates the 
other."


Christophe

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