There is clearly a speed benefit of just using cond, and sometimes it
can be the reason for the choice.
multimethods help you implement the Open / Close principle : they are
open to users providing more specific implementations for more
specific dispatch values. And for this it is not necessary for the
user of the multimethod to change existing implementations for certain
dispatch values (the close part).
There's certainly much to say about the differences, but here's my contribution.
HTH,
--
Laurent
I have a feeling multimethods could be useful for of plenty other
things, but so far that's all I've seen or done with them.
-Jeff
On Feb 11, 4:27 pm, Laurent PETIT <laurent.pe...@gmail.com> wrote:
> 2010/2/11 Bryce <fiat.mo...@gmail.com>:
the expression problem
(http://en.wikipedia.org/wiki/Expression_Problem) talks about some of
the relevant trade-offs.
sincerely.
You may also be interested in using pattern matching. It allows
dispatching based on structure or equality of your values, somewhat
similar to what you could do in Haskell or OCaml:
http://www.brool.com/index.php/pattern-matching-in-clojure
Being mostly a glorified cond, however, it shares the same lack of the
Open/Close principle, as Laurent put it. For the most trivial of
cases, when openness is not an issue, you may even get away with using
a map (as in some parts of clojure.contrib, I believe):
(def month-name {1 "January", 2 "February", 3 "March", ...})