Re:Clojure on the Google App Engine
by swannodette on Monday May 11, 2009 @04:45PM
(#604291)
No criticism of CLOS generic functions, but they accomplish something very different from Clojure multimethods. generic functions are intended to support objects. Clojure doesn't have objects, so Clojure does not limit multimethods to the kinds of use cases that generic methods are intended to solve.
Again you can dispatch on anything. Your dispatch function can return any value (a set, a hash-map, a vector, a list, a string, a number, etc.).
(defn new-dispatch
[x y z] (meta y))
(defmulti my-multi new-dispatch)
(defmethod my-multi {:meta-key1 meta-val1}
[x y z] ...)
(defmethod my-multi {:meta-key2 meta-val2}
[x y z] ...)
This one dispatches on the metadata attached to the second argument.
Again you can dispatch on anything. Your dispatch function can return any value (a set, a hash-map, a vector, a list, a string, a number, etc.).
(defn new-dispatch [x y z] (meta y))
(defmulti my-multi new-dispatch)
(defmethod my-multi {:meta-key1 meta-val1} [x y z] ...)
(defmethod my-multi {:meta-key2 meta-val2} [x y z] ...)
This one dispatches on the metadata attached to the second argument.