On Oct 12, 11:27 am, CuppoJava <[EMAIL PROTECTED]> wrote:
> Never mind my previous post. I realized my problem doesn't have
> anything to do with threads at all. What I'm really asking is: Is it
> possible for a closures to automatically capture a dynamic variable?
>

They wouldn't be dynamic then. Remember all defns are closures too.
Referencing a dynamic var means saying "I want the current thread-
local value". If you want something else then take an argument, or
arrange for the binding to be what you want >>when executed<<. The
values when the closure is created are irrelevant.

> ie. The following doesn't work as you expect:
>
> (def env)
> (defn create-fn []
>     (fn [] (println env)))
>

You'll need to revise your expectations, since they conflict. For
example, if I were to say:

(binding [*out* somewhere]
 ((create-fn)))

I presume you would expect env to print to somewhere, but with
closures capturing dynamic vars, it would instead print to whatever
*out* was bound to when println was defined.

Such a system would render dynamic vars non-dynamic.

Rich

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to