On Aug 27, 4:37 am, Terje Dahl <te...@terjedahl.no> wrote: > I was surprised to discover that the following was possible: > > (let [ > x 1 > y 2 > x (+ x y) ] > x ) > > This runs and returns 3! > > This feels an awful lot like variables and procedural programming. > It is left up to the developer to not resetting a "variable" - by > convention - and if he reset the identifiers, he ends up with hard-to- > debug spagetti-code. > > I would have thought that the system would have protested when I > attempted to set 'x' to a new value! > Amit Rathore writes in "Clojure In Action" about : "[...] are locally > named values (they are like variables, but they can’t vary since > Clojure’s data-structures are immutable)" > > In combination underscore identifiers for throw-away return values, > one can in fact write a whole procedural program within the vector > parens of a let-statement! Congratulations, you have discovered what most compilers for imperative languages do under the hood with static single assignment form. > Perhaps this is something that should be changed in future versions of > the language?! Restricting this would be a bad idea, as restricting this would me restricting the shadowing of locals, which would make code harder to understand.
For example, is this piece of code legal? (let [x 5] (* x 2)) Currently it is. However, if we restricted the shadowing of locals, it may or may not be -- you cannot tell unless you look at the surrounding context. -- 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