On Dec 11, 5:37 pm, Ken Wesson <kwess...@gmail.com> wrote: > On Sat, Dec 11, 2010 at 3:32 AM, Alexander Yakushev > > Making the thing work with (name args ...) is not too too difficult. > You'd have to have defmethod output both a def of an atom like above, > but with a gensym for a name, and a defn with the specified name that > has the body of call-method, more or less, but with the name arg fixed > to the gensym. There'd also need to be a global names-to-gensyms table > somewhere to make addmethod and the like work. > > This variation looks like (defmacro defmethod [name dispatch-fn] `(do > (def ...) (defn ~name ...))). > > Another alternative is for defmethod to def the name to a function > that closes over the atom and, via special sentinel arguments, > implements all the functionality of addmethod etc. as well as > call-method. When called without sentinel arguments it does a normal > call-method; when called as (name :add dispatch-val meth) it adds a > method; etc. > > This variation looks like (defmacro defmethod [name dispatch-fn] `(def > ~name (let [a (atom ...)] (fn ...)))).
Thanks a lot! That was particularly what I was asking. I got the idea of defining some map of dispatch-values - functions, but my thoughts ended up either at defining multimethod macro and multimethod map atom separately, or using syntax like ((call method-name) args...). The last part of your response was a great help for me! -- 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