I better take this off line. I'm getting sloppy. Back to it later. On Tue, Nov 24, 2015 at 9:50 AM, William la Forge <laforg...@gmail.com> wrote:
> It occurs to me that this can be simplified by using defrecord in place of > deftype. We can eliminate the Composite interface, because compositeMap > becomes the identity function. The code now becomes: > > (def blip [this x y z] ((:blip this) this x y z)) > (defprotocol gran > (blip this x y z)) > (defrecord wackel) > (defn new-wackel [opts] (assoc opts :blip (fn [this x y z] (+ x y z))) > (extend wackel > gran > {:blip blip}) > > This is better, but still a bit to swallow. Also, note I fixed a bug in > new-wackel. > > > On Tue, Nov 24, 2015 at 9:37 AM, William la Forge <laforg...@gmail.com> > wrote: > >> So lets look at some artifacts then. I think we need an interface that >> all composites implement: >> >> (definterface Composite >> (compositeMap [])) >> >> The function composite-map returns the map which holds the aggregated >> functions and data. >> >> Now lets look at a sample function, blip: >> >> (def blip [^Composite this x y z] ((:blip (.compositeMap this)) this x y >> z)) >> >> and a protocol that includes blip: >> >> (defprotocol gran >> (blip ^Composite this x y z)) >> >> Next we define a type which will hold an aggregate that includes an >> implementation of blip: >> >> (deftype wackel [my-map] >> Composite >> (defn compositeMap [_] my-map)) >> >> and a function to create an instance of that type: >> >> (defn new-wackel [this opts] (assoc opts :blip (fn [this x y z] (+ x y >> z))) >> >> Finally, we can extend our type with the protocol: >> >> (extend wackel >> gran >> {:blip blip}) >> >> I find this uncomfortable. In Rich's terms this is simple but hard. To be >> expected, as it is a major decomplection. But it will take me a while to >> get comfortable with this. :-( >> >> --b >> >> >> > > -- 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.