On Wednesday, 3 April 2013 00:39:25 UTC+5:30, larry google groups wrote: > > > If Clojure is suppose to emphasize immutability, why can I do this: > > kiosks-clojure.core=> (let [ > #_=> mega (+ 1 1) > #_=> mega (+ 1 mega) > #_=> mega (+ 1 mega) > #_=> mega (+ 1 mega) > #_=> mega (+ 1 mega)] > #_=> mega) > 6 > > I might as well be writing PHP code. >
In PHP and other imperative language `mega` is a "place" (as in place oriented programming.) Consider this: (let [mega 0] (let [mega (+ 1 mega)] (println mega)) (println mega)) Output: 1 0 In Clojure a symbol is bound to a value (both are otherwise independent) in a scope. Bindings can nest and unwind like a stack. In PHP a variable is tied to the "place" that can be updated but cannot nest. So, consider this PHP snippet: $mega = 0; $mega = 1 + $mega; echo $mega; // prints 1 echo $mega; // still prints 1 because it didn't unwind When we say (let [foo 20 foo (+ 5 foo)] ..) we basically rebind within the same let form and it's a convenience to rebind a local to a new value due to intermediate computation step. Shantanu -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.