Functions (methods as you call them) can have several bodies depending on the number of arguments, for example: (defn stupid-max ([a] a) ([a b] (if (> a b) a b)) ([a b c] (stupid-max (stupid-max a b) c)))
Mutlimethods decided which function to call depending on the value of a dispatch function. For example:(defmulti make-noise :type) (defmethod make-noise :dog [obj] (println "whoof whoof")) (defmethod make-noise :cat [obj] (println "miao")) (defmethod make-noise :duck [obj] (println "quack quack")) (make-noise {:type :duck :name "duffy"}) You can read more about multimethods http://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Examples/Multimethod HTH, -- Miki On Sep 1, 9:26 pm, HB <hubaghd...@gmail.com> wrote: > Hey, > How a multimethod in Clojure differs from a method that have multiple > bodies? > When to use each approach? > Thanks. -- 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