On Feb 11, 4:04 pm, Bryce <fiat.mo...@gmail.com> wrote:
> I'm wondering what the rationale is for using multimethods vs. cond,
> and where it's best to use either?  Multimethods seem to be very
> seldom used, usually to dispatch on type, but I can see advantages to
> using data to dynamically define only the methods you need, rather
> than having all-encompassing cond statements.  It also seems like
> generally cleaner code.  Is there a speed benefit to one or the other?

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", ...})

-- 
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

Reply via email to