Thanks Itay, that's exactly what I need.

On Thu, Mar 5, 2009 at 1:15 PM, Itay Maman <itay.ma...@gmail.com> wrote:
>
> Here's how plugin support is implemented in Waterfront:
>
> The last expression in each plugin is the "plguin init function": a
> function (can be anonymous) that takes a single parameter (a map) and
> returns new map.
> The load-plugin function takes a strings (specifying the path to
> a .clj file), and performs load-file on each string. Then, load-plugin
> evals the value returned by load-file (which, in fact, is the plugin
> init function) passing a map as a parameter. If you're loading several
> plugins the result returned from the init function will be used as the
> new map passed to the next plugin.
>
> Anyway, enough talking, let's go coding:
>
> ; say myutil/ut1.clj contains
> (ns 'myutil.ut1)
> (defn foo [] :foo-ut1)
>
> ; init function of ut1
> (fn [m] (assoc m :foo foo))
>
>
> ; and myutil/ut2.clj contains
> (ns 'myutil.ut2)
> (defn foo [] :foo-ut2)
>
> ; init function of ut2
> (fn [m] (assoc m :foo foo))
>
>
> (defn load-plugin [path]
>  ((load-file path) {}) )
>
> ;mylib/lib1.clj
> (defn libfoo []
>  (((load-plugin (if some-condition "myutil/ut1.clj" "myutil/
> ut2.clj")) :foo)) )
>
>
>
> That's it. In Waterfront this design is integrated with the context
> pattern which I described here a few days ago.
>
> Hope that helps.
>
> --
> Itay Maman
> http://javadots.blogspot.com
>
> On Mar 5, 6:48 am, Adrian Cuthbertson <adrian.cuthbert...@gmail.com>
> wrote:
>> Hi,
>>
>> How would one create a "plugin" modular composition using clojure
>> functions/modules only (i.e without resorting to java interface/
>> plugin class implementations)?
>>
>> For example;
>> ; say myutil/ut1.clj contains
>> (ns 'myutil.ut1)
>> (defn foo [] :foo-ut1)
>>
>> ; and myutil/ut2.clj contains
>> (ns 'myutil.ut2)
>> (defn foo [] :foo-ut2)
>>
>> ;and mylib/lib1.clj contains
>> (defn libfoo [] (foo))
>>
>> Then from my app, I'd like to tell mylib.lib1 which ut to use when it
>> loads, before calling libfoo.
>> Is this possible, or is there some other clojure way of doing this?
>>
>> Thanks,
>> Adrian.
> >
>

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