Re: binding issue

2009-07-17 Thread Jonathan Smith
On Jul 14, 5:12 pm, Stuart Sierra wrote: > On Jul 14, 3:01 pm, bgray wrote: > > > Ok, so *if* this is intended behavior, what have people been doing to > > bind variables dependant on other bindings?  I can't be the first to > > run into this. > > Just nest multiple binding forms: > (binding [

Re: another binding issue?

2009-07-14 Thread Kevin Downey
this is how you do it: user=> (def a 0) #'user/a user=> (binding [a 1] (map #(+ % a) (range 5))) (0 1 2 3 4) user=> (binding [a 1] (let [a a] (map #(+ a %) (range 5 (1 2 3 4 5) user=> you capture the dynamic scope in the lexical scope so the closure can close over it. dunno how applicable t

Re: another binding issue?

2009-07-14 Thread Mark Engelberg
It almost seems like what you want is for lazy data structures to close over the dynamic vars that have been modified from their root bindings at the time the lazy data structure is created. Seems like coming up with well-defined semantics for this would be an interesting research problem, and if

Re: binding issue

2009-07-14 Thread Meikel Brandmeyer
Hi, Am 14.07.2009 um 21:01 schrieb bgray: Ok, so *if* this is intended behavior, what have people been doing to bind variables dependant on other bindings? I can't be the first to run into this. I haven't run into this, but there are two obvious approaches: (let [new-a (compute n e w a)]

Re: binding issue

2009-07-14 Thread Stuart Sierra
On Jul 14, 3:01 pm, bgray wrote: > Ok, so *if* this is intended behavior, what have people been doing to > bind variables dependant on other bindings?  I can't be the first to > run into this. Just nest multiple binding forms: (binding [a ...] (binding [b ...] ...)) Not pretty, but it do

Re: another binding issue?

2009-07-14 Thread Kevin Downey
closures capture lexical scope, binding creates dynamic scope. lexical scope is where a closure is defined, dynamic is when it is called. because filter is lazy, the closure is called outside the dynamic scope created by binding On Jul 14, 1:07 pm, Aaron Cohen wrote: > I'm a little unclear on w

Re: another binding issue?

2009-07-14 Thread Aaron Cohen
I'm a little unclear on why this happens still. #(= % a) is a closure, correct? My understanding is that this should capture the environment when it is defined. Why does "the environment" not include the current bindings? -- Aaron On Tue, Jul 14, 2009 at 4:03 PM, Mark Engelberg wrote: > > On

Re: another binding issue?

2009-07-14 Thread Mark Engelberg
On Tue, Jul 14, 2009 at 12:40 PM, Jarkko Oranen wrote: > This is a common gotcha. It's actually a laziness issue: the seq > produced by filter is realised only after it exits the binding scope, > thus producing '(1). You need to use "doall" to force the seq if you > want the binding to apply. Yea

Re: another binding issue?

2009-07-14 Thread bgray
That makes sense. Thanks for the quick help! On Jul 14, 2:40 pm, Chouser wrote: > On Tue, Jul 14, 2009 at 3:04 PM, bgray wrote: > > > I'm not sure if this is a binding issue or not. > > > user=> (def a 1) > > #'user/a > > user=> (binding [

Re: another binding issue?

2009-07-14 Thread Jarkko Oranen
On Jul 14, 10:04 pm, bgray wrote: > I'm not sure if this is a binding issue or not. > > user=> (def a 1) > #'user/a > user=> (binding [a 3] (filter #(= % a) '(1 2 3))) > (1) > user=> > > In this case, I was expecting a list with 3 in it. This

Re: another binding issue?

2009-07-14 Thread Chouser
On Tue, Jul 14, 2009 at 3:04 PM, bgray wrote: > > I'm not sure if this is a binding issue or not. > > user=> (def a 1) > #'user/a > user=> (binding [a 3] (filter #(= % a) '(1 2 3))) > (1) > user=> > > In this case, I was expecting a li

another binding issue?

2009-07-14 Thread bgray
I'm not sure if this is a binding issue or not. user=> (def a 1) #'user/a user=> (binding [a 3] (filter #(= % a) '(1 2 3))) (1) user=> In this case, I was expecting a list with 3 in it. Thanks, Brandon --~--~-~--~~~---~--~~ You received

Re: binding issue

2009-07-14 Thread bgray
Ok, so *if* this is intended behavior, what have people been doing to bind variables dependant on other bindings? I can't be the first to run into this. Thanks! Brandon On Jul 12, 12:05 am, Tom Faulhaber wrote: > Looking at the clojure docs, it doesn't appear to be defined whether > binding is

Re: binding issue

2009-07-11 Thread Tom Faulhaber
Looking at the clojure docs, it doesn't appear to be defined whether binding is a parallel (all vars are computed based on the initial state) or sequential (vars are computed using the new values for vars used in the same binding vector). A quick test shows that it appears to be parallel: (bindin

binding issue

2009-07-11 Thread bgray
Is this behavior expected from binding? user=> (def a nil) #'user/a user=> (def b nil) #'user/b user=> (binding [a 1 b (+ a 1)] a) java.lang.NullPointerException (NO_SOURCE_FILE:0) user=> (binding [a 1 b (+ a 1)] b) java.lang.NullPointerException (NO_SOURCE_FILE:0) user=> (let [a 1 b (+ a 1)] a)