Yeah, in practice it seems like multimethods are pretty much just used
as a way to let users of a library extend the API to support
additional types.  If you had a cond expression dispatching on the
type of an argument, for example, then the user would have to modify
the source code of your library to add support for their custom type.
With multi-methods the user can implement a method defined in the
library that dispatches on their own type, and the code can stay
within their own project.

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

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