On Dec 1, 10:56 pm, Rich Hickey <richhic...@gmail.com> wrote: [snip] > There are 2 ways to make a deftype reach a protocol. First, you can > implement the protocol directly in the deftype/reify, supplying the > protocol where you do interfaces, and the methods of the protocol as > methods of the type. The type will be made to implement the protocol's > interface.
OK. With extend you can use maps and merge to share implementations. Does directly implementing the protocol in deftype allow also for "abstract super-classes", i.e., sharing protocol-function implementations across types? [snip] > Different methods of implementing the protocol have different > performance. Implementing directly in deftype or reify is as fast as a > direct interface call. Using extend-* is not quite as fast, but still > fast. Both methods have direct support in callsites, so a call to a > protocol fn has support both for using the interface and caching > lookup results. Great. So the preferred way for data-types in my program is to implement the protocol directly, whereas for other types I can still use my protocol with extend. Just to confirm my understanding: Is it correct to say, for example, that clojure.lang.Seqable will be a protocol implemented directly in the Clojure data types, whereas it would reach the Java lang types using extend? In Clojure-in-Java interfaces like IPersistentCollection extend Seqable: would these be unrelated type-wise as protocols? > The most important thing is, writing to protocols gives you a dynamic, > open, extensible system not tied to derivation, and is fast, so a > great way to architect the polymorphic part of your designs (when > single-dispatch is appropriate). > > Rich I think these constructs will have great impact on how we will structure our Clojure programs. /Karl -- 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