Thank you very much for the explanation. On 3 February 2017 at 21:04, pd <eukel...@gmail.com> wrote:
> The reason for this difference is let behaviour: let binds a symbol to a > value *inside* let expression but first saves values of binding symbols and > once evaluated the expression it restores previous symbols values saved. > > So, when you wrap a expression in a let binding you are protecting the > symbols values for further modification, each internal wrapping with let > gives you a layer of protection. > > In first version you protect the expression in a let wrapping, the > expression (the let body) may change symbols in any way because after being > evaluated (let's say when exiting let function) the symbol value of symbols > bound by let will be restored to previus value. But *inside* the clause > changes happen! > > : (let X 0 # let binds symbol X to 0 *inside* let > expression (the following line) > (for Y 3 (inc 'X) (prinl X)) # in this let expression every change > to symbol X takes effect, in particular incrementing it > ) # after execution of let expression > binding symbols are restored to saved value (in this case without more > information it shoud be NIL) > > But in second version you add an extra protection layer to the expression > by wrapping it in a let binding, as always expressions may change symbols > inside let expression but now they are protected by a internal let layer > which "hides changing effects" > > : (let X 0 # let binds symbol X to 0 *inside* let expression > (the following lines) > (for Y 3 > (let X (inc 'X) # but now you have an extra let protecction layer > which binds X thus protecting it for changes made in inner let expression > by saving current X value (0) > (prinl X) # this is inner let expression, prints the value > of inner X binding (which is always 1 because is always incrementing 0 by 1 > as we will see) > ) # at this point let restores value of symbol X to > previous value , which is 0 as set by outer let binding > ) # so each step of for loop symbol X has value 0 > (because is setted by outer let and restored by inner let) and thus get > incremeted to 1 > ) > > So as you can see let is used to isolate actions without affecting current > symbol values, you can think of it as "hiding actions" You can think about > it in terms of lambda applications which may be easier to understand (if > you're interested let me know ;-) > > As picolisp seem not to have a let* like in classical lisp I assume let > bindings are done in parallel as traditionally let behaves in classical > lisp, sure Alex can state it clearly > > > On Thu, Feb 2, 2017 at 7:20 PM, dean <deangwillia...@gmail.com> wrote: > >> Just to illustrate what I meant... >> : (let X 0 >> (for Y 3 >> (let X (inc 'X) (prinl X)))) >> 1 >> 1 >> 1 >> -> 1 >> >> On 2 February 2017 at 18:16, dean <deangwillia...@gmail.com> wrote: >> >>> Thank you very much for the advice....I've just used that and it's >>> worked a treat.... >>> >>> : (let X 0 >>> (for Y 3 >>> (inc 'X) (prinl X))) >>> 1 >>> 2 >>> 3 >>> -> 3 >>> >> > > -- > Andrés > > *~ La mejor manera de librarse de la tentación es caer en ella**. ~ Oscar > Wilde* ~ >