Re: binding funkiness

2013-04-23 Thread Daniel Higginbotham
That clears things up completely. Thanks for the help, everybody! On Monday, April 22, 2013 10:48:11 PM UTC-4, tbc++ wrote: To simplify the problem: ((binding [*funkybind* true] (fn [] *funkybind*))) This is the same problem as your lazy-seq example. The issue is that *funky-bind* is

binding funkiness

2013-04-22 Thread Daniel Higginbotham
I've encountered a situation where the binding function doesn't work as I expect it: user (def ^:dynamic *funkybind* false) ;; expected user (binding [*funkybind* true] *funkybind*) true ;;expected (binding [*funkybind* true] ((fn [] *funkybind*))) true ;;... huh? (binding [*funkybind*

Re: binding funkiness

2013-04-22 Thread Travis Vachon
Hi Daniel map is creating a lazy seq, which isn't evaluated until the REPL's forces it to be printed, which is outside the scope of the binding. This: (binding [*funkybind* true] (doall (map (fn [_] *funkybind*) [1 2]))) forces evaluation inside the binding, and does what you want. This is

Re: binding funkiness

2013-04-22 Thread Carlo Zancanaro
If you want to capture the binding and have laziness together you can also use `bound-fn`. (binding [*funkybind* true] (map (fn [_] *funkybind*) [0 1])) ;= (false false) (binding [*funkybind* true] (map (bound-fn [_] *funkybind*) [0 1])) ;= (true true) On Tue, Apr 23, 2013 at 11:52 AM, Travis

Re: binding funkiness

2013-04-22 Thread Timothy Baldridge
To simplify the problem: ((binding [*funkybind* true] (fn [] *funkybind*))) This is the same problem as your lazy-seq example. The issue is that *funky-bind* is not deref'ed when the anonymous fn is created, but when it is executed. In this example, by the time the fn is executed, *funkybind*