On Mar 7, 1:09 am, Tassilo Horn <tass...@member.fsf.org> wrote: > David Powell <d...@djpowell.net> writes: > > Hi David, > > > When you create a protocol, as an implementation detail, it also > > creates a Java interface. > > Is a protocal neccessarily an implementation detail? I mean, it might > be, but it can also be a public specification of the requirements types > have to satisfy in order to integrate with my lib.
You misread his assertion. The implementation detail is that an interface is defined along with each protocol. > > When you list protocols in a deftype or defrecord form, the generated > > class actually implements that Java interface. And protocol calls to > > that type call through the interface. This gives the best performance. > > > If you add protocols to an existing class, record or type; this > > dispatch is done dynamically and interfaces aren't involved. > > That suggests that `extenders' is actually a private function for doing > the dynamic dispatch. But it's not used at all in clojure.core. And > it's inconsistent with extends?. I don't really see how it suggests that, but okay. It does appear that you're right that extenders and extends? are not consistent between each other. > user> (defrecord R2 [] Bashable (boom [this] :boom)) > user.R2 > user> (extenders Bashable) ;; just returns the "dynamic" extenders > (user.Record) > user> (extends? Bashable R2) ;; does an implements? check as well > true > > IMHO, `extenders' should return also types implementing the protocol > interface directly, so that > > (extends? P T) <=> (some #(= % T) (extenders P)) > > holds. You're entitled to that humble opinion, but it's not really possible with any kind of reasonable performance. When you implement the protocol interface directly, no machinery in clojure.core gets involved at all - you just define a class that implements an interface. For `extenders` to be able to list Java classes that implement the interface directly, it would have to walk through every class loaded in the JVM and check its implemented-interfaces. Of course, you could make it almost-work, by having deftype/defrecord emit some special code for hooking into extenders whenever you define a class in Clojure, but then it would only work for classes defined within Clojure, and not for Java classes that implement Clojure's interfaces/protocols. Frankly I think that's worse than just limiting it to "dynamic" extenders. -- 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