Thanks for the reply, Nils.

2011/12/1 Nils Bertschinger <nils.bertschin...@googlemail.com>

> Hi Roman,
>
> as far as I understand, the Clojure compiler is doing some
> optimizations for recursive functions to save the variable lookup.
> This means that you have to explicitly write the recursive call as
> (#'fact (dec n)) if you want to dynamically rebind the function.
> Somehow this doesn't feel right for a dynamic language.


> Clojure 1.3, which cannot dynamically rebind variables unless they are
> explicitly marked as ^:dynamic, introduced with-redefs to solve this
> problem. In Clojure 1.3 you're example works as expected if you use
> with-redefs instead of binding in the definition of fact-with-logging.
> In case you can't use Clojure 1.3, you might be able to use the source
> code of with-redefs in order to achieve a similar effect in 1.2.
> Though, I haven't tested it.
>

I upgraded to clojure 1.3 and indeed it works correctly when I use
with-redefs. The only downside is that changes made by with-redefs are
visible in all threads.

Do I understand correct that the only way to hook a recursive function
without affecting other threads is to annotate the function with ^{:dynamic
true} and call it via #'fact?

Roman.

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