Alex Osborne wrote: > Chick Corea wrote: >> If I understand correctly, the "(binding ...)" macro specifically >> applies to >> "Variables", one of Clojure's STM types, thus has dynamic, thead-local >> scope. Is that right? In which case, it may hide a lexical binding ? > > Yes, I think you are basically correct. Maybe this example will help:
No it won't because I totally messed it up (copy-paste errors). Sorry, I'm not completely awake yet. What I meant was: (def x 5) ; thread-global nearly immutable root binding (binding [x 7] ; creates a thread-local binding for x (set! x 9) ; changes the thread-local binding (let [t (Thread. (fn [] (println "x in other thread:" x) (set! x 25)))] (.start t) (.join t)) (println "x in main thread:" x) (def x 72) ; change root-bindings (don't do this!) (println "x in main thread after 2nd def:" x)) (println "x outside binding:" x) Output: x in other thread: 5 Exception in thread "Thread-188" java.lang.RuntimeException: java.lang.IllegalStateException: Can't change/establish root binding of: x with set x in main thread: 9 x in main thread after 2nd def: 9 x in outside binding: 72 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---