> > So how to do this? As far as I can tell, these various modules are > all "hard-linked" to point at one another, and I don't see how to make > this linkage more dynamic. To change one file, I'd have to create new > versions of ALL the files. It would be great if each file could store > a variable for what namespace it needs to use to get at the other > functions. For example, the generator has a variable that points at > the solver namespace, and accesses the solver functions through that > variable. Then, you could have one master file that loads the > particular versions of the modules you want, and links them to one > another. But I really don't see how such glue could be written. Any > suggestions? >
I don't know if this is any better than approaches suggested by others, but consider the following: (ns solver) (defn solve [x] x) (ns generator (:use [solver]) (def *gravity* 1.0) (defn gen-fn [] (let [grav *gravity* sol-fn solver/solve] (fn [x] (sol-fn (* x grav))))) _______________________ At the REPL- (def f0 (binding [*gravity* 2.0] (gen-fn))) Then when you want to test a change to a function in the solver namespace: (def f1 (binding [*gravity* 2.0 solver/solve (fn[x] (/ x 5))] (gen-fn))) Others have suggested using binding - the difference here is that you create closures around specific values of the vars you expect you will want to change. This avoids the problem with binding and laziness and multiple threads - once you create the closure you capture and persist the value of the dynamic var for all threads to see at any time in the future. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---