if only lisp had macros On Fri, Jul 8, 2011 at 12:16 PM, David Jagoe <davidja...@gmail.com> wrote: > Hi All, > > I am battling with how to deal with the difference between Protocols > and Interfaces in a particular case. > > Consider the following code: > > (defrecord DomainTypeA [] > SomeInternalProtocol > (foo [this] "foo result") > > clojure.lang.IFn > (invoke [this] "invoke result")) > > This code works fine. > > However, I have a number of domain types all of which must use the > same implementation of foo and invoke. > > In the case off foo its easy: > > (defrecord DomainTypeA []) > (extend DomainTypeA SomeInternalProtocol internal-protocol-implementation-map) > > However I cannot do: > > (extend DomainTypeA clojure.lang.IFn some-implementation) > > because IFn is a java Interface. How would I get arount this? > > My use case is as follows: > > Every one of my domain objects needs to implement invoke in the same > way, so I don't want to code it in-line on the record definition each > time. The implementation is defined in one place and I eventually want > a macro (e.g. defdomainobj but with a better name!) that would > automatically hook up the IFn def. > > Hmm maybe I just answered my own question: > > Should I just write the macro that spits out the code in my first listing? > > Thanks! > > Cheers, > David > > -- > 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
-- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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