Instead of using "alter-var-root" you could use the "binding" form. On this
subject of factory methods you could find useful the following article,
expecially the "with-implementation" macro:

http://pragprog.com/magazines/2011-07/growing-a-dsl-with-clojure

IMHO that solution should not prevent the callers from instantiate
different implementations of the same generic API, even from the same
thread.

Cheers,
Roberto


On Sat, May 12, 2012 at 2:49 PM, James Thornton <james.thorn...@gmail.com>wrote:

>
> On Saturday, May 12, 2012 12:44:45 AM UTC-5, Baishampayan Ghose wrote:
>>
>>
>> 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
>>
>
> I was experimenting with the dynamic varr approach...
>
> ;; bulbs/neo4jserver/client.clj
>
> (def ^:dynamic *config* default-config)
>
> (defn set-config!
>   [config]
>   (alter-var-root #'*config* (fn [_] (merge default-config config))))
>
> (defn neo4j-client
>   [& config]
>   (set-config! (first config)))
>
> (neo4j-client {:root_uri "http://localhost:7474/data/db/"})
>
> (println *config*)
>
>
> ...but Andrew Cooke pointed out that using a global var would preclude you
> from being able to use multiple, independent graph "instances" in your
> program, whereas you can in the Python version (
> http://stackoverflow.com/questions/10540999/how-to-configure-a-clojure-library-at-runtime
> ).
>
>

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

Reply via email to