Question about transitivity in MultiFn.prefers() --- possible bug

65 views
Skip to first unread message

John Alan McDonald

unread,
Aug 12, 2017, 9:32:30 PM8/12/17
to Clojure
prefers(x,y) checks the ancestors of x, and returns true if any of them are preferred to y --- which makes sense to me.

However, it also check the ancestors of y, and returns true if x is preferred to any of them, which I don't understand. 
Is that the intended behavior?  Seems like it should be checking the descendants of y.
What I am I missing?

John Alan McDonald

unread,
Aug 14, 2017, 5:57:47 PM8/14/17
to Clojure
A related but slightly different issue: is prefer-method supposed to be transitive?
That is,  (prefer-method f a b) and  (prefer-method f b c) implies (prefer-method f a c)?
Here is a unit test that checks for transitivity (which fails in Clojure 1.8.0):

(test/deftest transitive
  (derive ::transitive-d ::transitive-a)
  (derive ::transitive-d ::transitive-c)
  (defmulti transitive identity)
  (defmethod transitive ::transitive-a [x] [::transitive-a x]) 
  (defmethod transitive ::transitive-c [x] [::transitive-c x]) 
  (prefer-method transitive ::transitive-a ::transitive-b)
  (prefer-method transitive ::transitive-b ::transitive-c)
  (test/is (= [::transitive-a ::transitive-d] 
              (transitive ::transitive-d))))


Reply all
Reply to author
Forward
0 new messages