On Thu, Apr 26, 2012 at 23:35 -0700, Sean Corfield wrote:
> On Tue, Apr 24, 2012 at 8:30 PM, Michael <michael-a...@db.com> wrote:
> > Would it be possible to make resultset-seq a dynamic var
> 
> No, that certainly is not going to happen. Dynamic vars are not the
> right way to build an API in Clojure.

Could you elaborate on that please? I see that dynamic variables are used quite
often to give the user the ability to configure/change the behaviour of a
library. That approach is often coupled with a macro that changes the bindings
of dynamic variables. An example of this can be, for example, found in
criterium [0]

--- snip ---
;;; Progress reporting
(def ^{:dynamic true} *report-progress* nil)

(defn #^{:skip-wiki true}
  progress
    "Conditionally report progress to *out*."
      [& message]
        (when *report-progress*
            (apply println message)))
            
(defmacro with-progress-reporting
  "Macro to enable progress reporting during the benchmark."
    [expr]
      `(binding [*report-progress* true]
           ~expr))
--- snip ---

I guess that my confusion stems from your very general statement and my
inexperience so I would be happy if you could give more details. I find using a
dynamic variable in a library in the way exemplified above to be OK and maybe
(??) even idiomatic. It is just hard to "get" Clojure idioms right if a voice
keeps nagging in the back of your head saying "Dynamic vars are not ..."

Thanks!
-- 
Wolodja <babi...@gmail.com>

4096R/CAF14EFC
081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC

Attachment: signature.asc
Description: Digital signature

Reply via email to