prefers(x,y) visits ancestors by calling parents.invoke() recursively.
This visits the parents in the global hierarchy, not the multimethod's
hierarchy.
Is this the intended behavior? Why would that be?
On the assumption that prefer-method should behave the same for a local vs
the global-hierarchy, below are 2 unit tests.
MultiFn-prefers-with-local-hierarchy fails with a "Multiple methods"
IllegalArgumentException.
MultiFn-prefers-with-global-hierarchy succeeds.
(test/deftest MultiFn-prefers-with-local-hierarchy
(def local-hierarchy
(let [h (make-hierarchy)
h (derive h ::c0 ::b0)
h (derive h ::d0 ::c0)
h (derive h ::d0 ::a0)]
h))
(defmulti local identity :hierarchy #'local-hierarchy)
(defmethod local ::a0 [x] [::a0 x])
(defmethod local ::c0 [x] [::c0 x])
(prefer-method local ::b0 ::a0)
(test/is (= [::c0 ::d0] (local ::d0)))))
(test/deftest MultiFn-prefers-with-global-hierarchy
(derive ::c1 ::b1)
(derive ::d1 ::c1)
(derive ::d1 ::a1)
(defmulti global identity)
(defmethod global ::a1 [x] [::a1 x])
(defmethod global ::c1 [x] [::c1 x])
(prefer-method global ::b1 ::a1)
(test/is (= [::c1 ::d1] (global ::d1))))
--
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
---
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 [email protected].
For more options, visit https://groups.google.com/d/optout.