Nope, you're right, I missed the "extend, extend-type, extend-protocol" part of the original post.
On Thu, Nov 8, 2018 at 10:12 AM Alex Miller <a...@puredanger.com> wrote: > > On Thursday, November 8, 2018 at 10:44:34 AM UTC-6, tbc++ wrote: >> >> The instance based polymorphism is a bit wonky in some cases. Can we get >> some sort of spec that tells us what the rules are for resolution? >> > > From the top of the thread: "Protocol implementations are checked first > for direct definitions (defrecord, deftype, reify), then metadata > definitions, then external extensions (extend, extend-type, > extend-protocol)." Was that unclear in some way? I think it explains > everything you're seeing. > > We do plan to update the protocols reference page for final release, but > waiting on that. > > We are still doing performance eval on this too - still might change a bit > more. > > > > >> See these cases where it breaks in some rather strange ways. >> >> Clojure 1.10.0-beta5 >> user=> (defprotocol ILevel (level [this])) >> ILevel >> user=> (extend-protocol ILevel >> clojure.lang.IPersistentVector >> (level [this] "interface")) >> nil >> user=> (extend-protocol ILevel >> Object >> (level [this] "object")) >> nil >> user=> (level []) >> "interface" >> user=> (level :key) >> "object" >> user=> (level (with-meta 'foo {`level (fn [this] "instance")})) >> "instance" >> user=> (level (with-meta [] {`level (fn [this] "instance")})) >> "instance" >> user=> (defrecord MyType [] ILevel (level [this] "type")) >> user.MyType >> ;; Fails to override >> user=> (level (with-meta (->MyType) {`level (fn [this] "instance")})) >> "type" >> user=> (defrecord MyType3 []) >> user.MyType3 >> user=> (extend-protocol ILevel >> MyType3 >> (level [this] "type")) >> nil >> user=> (level (->MyType3)) >> "type" >> ;; Overrides >> user=> (level (with-meta (->MyType3) {`level (fn [this] "instance")})) >> "instance" >> user=> >> >> So it looks like if someone uses inline protocol extension that class >> cannot participate in instance level polymorphism. If however they use >> extend on the type after it's defined then the behavior changes and >> instance polymorphism is supported. >> >> >> -- > 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. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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.