Conceptually, the best way to think about it is that your binding sets the global x to 100 and restores the global x to 1 when exiting the scope of the binding construct. It has no effect on your local x.
Dynamic binding is confusing, and should be used with care. If you stick with the lexical scoping of function closures and lets, things should behave the way you expect. --Mark On Fri, Nov 20, 2009 at 7:40 PM, kunjaan <kunj...@gmail.com> wrote: > Even though I have used Clojure, I hadn't looked at the scoping rules > in detail. I am getting more confused as I read the documentations. I > made a small test to try out the scoping resolutions and am apalled at > the complexity. Could somebody explain the intent and various rules > that Clojure uses? > > (def x 1) > > (defn dummy-fn2[] > (+ x 1)) > > (defn dummy-fn[] > (println "entering function: " x) > (let [x 100] > (println "after let: " x) > (let [x (dummy-fn2)] > (println "after let and dummy2: " x) > (binding [x 100] > (println "after binding: " x) > (let [x (dummy-fn2)] > (println "after binding and dummy2: " x)))))) > > 1:2 foo=> (dummy-fn) > entering function: 1 > after let: 100 > after let and dummy2: 2 > after binding: 2 > after binding and dummy2: 101 > nil > > -- > 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 -- 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