On Fri, May 11, 2012 at 8:53 PM, James Thornton
<[email protected]> wrote:
> Is setting a dynamic binding at runtime the recommended way of storing the
> config map?
There are many ways of doing this. One approach that I have seen a lot
is something like this -
;; core.clj
(def ^:dynamic *settings* {:default :stuff}) ;; the default settings can be nil
(defmacro with-settings [settings & body]
`(binding [*settings* ~settings]
~@body)) ;; or something similar
;; so that the default can be set once and for all
(defn init! [settings]
(alter-var-root #'*settings* settings))
;; just use *settings*
(defn foo [x]
...)
(defn bar [x]
...)
;; user.clj
(foo 42) ;; will use the library provided defaults
(core/init! {:custom :settings})
(foo 42) ;; uses the custom settings
(bar "Sophie") ;; uses the custom settings
(with-settings {:my :settings}
(foo 42)
(bar "Sophie")) ;; will use the temporary settings
The code above is obviously for explanation only.
I hope that helps.
Regards,
BG
--
Baishampayan Ghose
b.ghose at gmail.com
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en