On Mon, Nov 23, 2009 at 2:26 PM, Sean Devlin <francoisdev...@gmail.com>wrote:
> * Back to Multimethods * > > The power of the individual closures can be amplified when wrapped in > a multimethod. Consider our String/Symbol/Keyword group. > > (defmulti visit-string (fn [& args] (second args)) > > (defmethod visit-string clojure.lang.Symbol > [f & args] > (apply visit-symbol f args)) > > (defmethod visit-string clojure.lang.Keyword > [f & args] > (apply visit-keyword f args)) > > (defmethod visit-string :default > [f & args] > (apply f args)) > > We now have a visit-string function that can truly visit anything. > Our function calls above become: > > (visit-string str-fn a-keyword args) > (visit-string str-fn a-symbol args) > Nifty. Of course, this naturally suggests a visit-coll to apply sequence operations on vectors, strings, and sets and return vectors, strings, and sets rather than generic seqs. :) -- 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