News for hackers. Stuff that matters.
Re:Clojure on the Google App Engine by mahmud on Monday May 11, 2009 @02:51PM (#604018)
I don't understand the need for defmulti.

  (defmethod my-add ((x integer) (y integer))
    (+ x y))

  (defmethod my-add ((x string) (y string))
    (concatenate 'string x y))

  CL-USER(8): (my-add 2 3)
  5
  CL-USER(9): (my-add "foo" "bar")
  "foobar"
Keep in mind you're dispatching on both arguments; the MY-ADD generic function is created for you and it's lurking in memory. You can add :before, :after and :around methods, which will allow you to get a hold of both arguments BEFORE the dispatch method is applied and after in a serial fashion, or AROUND the method dispatch altogether. This allows for stuff like logging, debugging, tracing, method wrapping and augmentation for moving-target type protocols and designs, etc.
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.