Hi Mark, I've used the following macro to achieve something like what you're doing;
In the file/namespace module (say eg_globs/fns.clj); (ns eg-globs.fns) (declare *gravity*) (defmacro with-grav [grav & body] `(let [gr# ~grav] (binding [*gravity* gr#] ~...@body))) (defn say-grav [] (prn "Gravity is:" *gravity*)) (defn halve-grav [] (/ *gravity* 2.0)) (defn mult-grav [x] (* *gravity* x)) Then in the calling module; (use 'eg-globs.fns) (with-grav 2.0 (say-grav) (prn "half:" (halve-grav)) (mult-grav 2.5)) "Gravity is:" 2.0 "half:" 1.0 5.0 (with-grav 1.5 (mult-grav 3.0)) 4.5 Hth, Adrian. On Sun, May 17, 2009 at 4:45 AM, Mark Engelberg <mark.engelb...@gmail.com> wrote: > > So I've built a file/namespace with several functions. There are > several globals defined at the top of the file (for example, > *gravity*) which many of the functions refer to. I made them globals > precisely because it would have been a pain to thread them through > every single function that uses them. > > Now, I need to maintain two versions of this module. For example, > let's say I want one module where the *gravity* constant is defined to > be 1.0, and one where it is defined as 2.0. > > I know how to do this in other languages, especially OO ones, but I'm > scratching my head trying to think of a clean solution in Clojure for > this seemingly simple problem. I've tried various namespace trickery > with vars and bindings, but I haven't found a workable solution yet. > What am I missing? Thanks. > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---