Re: mutability in the let-form!?

2011-08-27 Thread Ken Wesson
On Sat, Aug 27, 2011 at 10:24 AM, Brian Goslinga wrote: > 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. So, the restri

Re: mutability in the let-form!?

2011-08-27 Thread Ken Wesson
On Sat, Aug 27, 2011 at 6:05 AM, Alan Malloy wrote: > Stylistically, it's often not very nice to rebind x a number of times; > it's better to choose descriptive names for the intermediate steps. > But there are certainly times occasions where using the same name can > clarify meaning: for example,

Re: mutability in the let-form!?

2011-08-27 Thread Stuart Sierra
Hi Terje, The `let` form allows rebinding of symbols, which is not the same as mutability. In the form (let [x 1 y 2 x (+ x y)] x) the value of `x` does not change, rather the third line creates a new binding for `x`. The difference may seem trivial, but most func

Re: mutability in the let-form!?

2011-08-27 Thread Brian Goslinga
On Aug 27, 4:37 am, Terje Dahl 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 devel

Re: mutability in the let-form!?

2011-08-27 Thread Alan Malloy
Perhaps you'd be more comfortable considering this equivalent syntax: (let [x 1] (let [y 2] (let [x (+ x y)] x))) In principle, the multiple-binding let is transformed to this version and thus has identical semantics; in practice, the compiler does something more efficient but equival

mutability in the let-form!?

2011-08-27 Thread Terje Dahl
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