> One example, in the frontend we wrap all the database calls in a caching 
> layer but we don't need that when the same code runs in the backend. 
>

One option for something like this (a configuration option that doesn't 
change much between function calls/expected to largely remain the same for 
your program) is a dynamic var. You could just rebind eg *caching* to true, 
and your database calls could dispatch accordingly. 

Code loading is a first-order thing in Clojure as well, so you could do a 
conditional require:

(if *caching* (require '[db.cached :as db]) (require '[db.uncached :as db]))

I'm not sure if this is often done, though?

I am also interested in the answer to your question. I wonder If anyone's 
played with the idea of parameterized imports a la ML's functors:

(ns my-database-helpers
 (require ...)
 (args [& {:keys [db]}])

Then in the configuration code something like:

(require '[(my-database-helpers :db db.cached) :as helpers])

I know a big philosophy guiding Newspeak (http://newspeaklanguage.org/) is 
that ALL imports should be done this way-- no code should explicitly 
hard-code the libraries it uses.

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