Re: Clojure lambda funcs and bindings

2011-01-18 Thread Andreas Kostler
Maybe I didn't make myself clear enough. I'm implementing a scheme interpreter. The following function sets a variable in the given environment: (defn set-var! [var val env] "Set a variable to a value, in the given or global environment" (if-let [val ((keyword var) @env)] (reset! env (assoc @

Re: Clojure lambda funcs and bindings

2011-01-18 Thread Joost
Andreas Kostler wrote: > Hi all, > Suppose I have the following function: > (defn foo [x changeling] > (cond > (= (first x) 'bar) > (map #(foo % changeling) (rest x > > (def foobar (atom {:something "in-here"})) > > Now, changeling gets bound to (atom {:something "in-here"}). Erm

Re: Clojure lambda funcs and bindings

2011-01-18 Thread MiltondSilva
Now that I've read your e.g. a couple more times you seem to want to change the value of atom in foo. So first since you def the atom, there is no need to pass it to foo. Second when trying to see the value of the atom you deref it with @ and if you want to change it you use swap!, reset! or compar

Re: Clojure lambda funcs and bindings

2011-01-18 Thread MiltondSilva
Not sure if I understand your question/problem but, this: "How can I avoid the binding of changeling to the initial value of the atom and have the anonymous function passed to map use the current (possibly changed) value of changeling? " You are binding a reference not the actual value of the ato

Clojure lambda funcs and bindings

2011-01-18 Thread Andreas Kostler
Hi all, Suppose I have the following function: (defn foo [x changeling] (cond (= (first x) 'bar) (map #(foo % changeling) (rest x (def foobar (atom {:something "in-here"})) Now, changeling gets bound to (atom {:something "in-here"}). The conditional in foo might contain another ca