Hi, it looks more like a problem of dependency injection (which implementation for the interface, and who's responsible for choosing the implementation), so. (And now that I re-read the subject of your e-mail ... :-)
If we're just talking about switching the implementation of one function independently of other functions, then I think multimethod still can help. Indeed, nothing prevents you, in the dispatch function, to look for the value of a global variable (think singleton or Spring App Context key) which would be part of the dispatch value. Or create a generic "wrapper" function/macro you could use to replace your functions definitions, and this wrapper function could call an "application context function" that would return the real function to call ? There has also been in this ml some discussion about creating "modules", as far as I remember. Or create your functions sets in different maps [keys = symbol of function name, vals = functions] (one map ~= one "application context") and install as real defs one map or the other depending on some other parameter value .... Or just pass around the function implementation ... I'll let other speak on the subject now, 'cause I'm not sure I've even scratched the surface of possibilities, not to say I have possibly not given any good advice to you right now ... Regards, -- Laurent 2009/7/16 Dragan <draga...@gmail.com> > > Thanks for the tip, I meant something else. > Let's say that I want to write a function do-something. There could be > 2 implementations: do-something-quickly and do-something-elegantly. > The parameters are the same and there are no differences in their > "interface". I would like to be able to call it by writing (do- > something arg) in my code and specify which implementation I want to > use somewhere else (in the configuration part of the code). > > On Jul 16, 4:28 pm, Laurent PETIT <laurent.pe...@gmail.com> wrote: > > Certainly multimethods : > > * introduction :http://clojure.org/runtime_polymorphism > > * detail :http://clojure.org/multimethods > > > > And, also, don't forget the power given to you by first class / higher > order > > functions. With them, a lot of "variability" can be placed just in > > functions, where it was a pain in the ass to do correctly in java (you > have > > to first create an interface with a method, then derive the interface). > And > > often this was not done at all, and you ended up with a lot of similar > > functions when their size was too small, etc. > > > > HTH, > > > > -- > > Laurent > > > > 2009/7/16 Dragan <draga...@gmail.com> > > > > > > > > > Hi, > > > > > This is another one of my newbie questions, so please be patient if > > > this is something out of the FP paradigm. > > > I've noticed that there is a number of "duplicate" functions, > > > functions that implement the same thing in a different way. In OO > > > systems, I would use an interface to achieve the indirection. > > > What should I use in Cilojure? > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---