My first thought on seeing: (collide some-gaussjammer some-starship)
was "He's colliding two starships, he'll want (defmethod collide [::starship ::starship] ...)" In (what's left of) my OO brain, I think "That only requires one upcast on gaussjammer to starship in order to get an exact match" whereas the alternative match requires an upcast on both arguments. That may not actually be correct in any language but it's what seemed obvious to me ... Sean On Fri, Sep 14, 2012 at 9:30 AM, Brian Marick <mar...@exampler.com> wrote: > Here's a simplification of an exercise I was trying to write. We have a > two-level hierarchy of objects: > > (derive ::starship ::thing) > (derive ::gaussjammer ::starship) > > We have a generic function that uses both arguments: > > (defmulti collide (fn [one two] [(type one) (type two)])) > > We have these two specializations: > > (defmethod collide [::starship ::starship] ...) > (defmethod collide [::gaussjammer ::thing] > > Those are considered ambiguous in the face of: > > (collide some-gaussjammer some-starship) > > A `prefer-method` is required: > > (prefer-method collide [::gaussjammer ::thing] [::starship ::starship]) > > Why? In what cases would a programmer prefer something like the second match? -- 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