Re: looping

*To*: mathgroup at smc.vnet.net*Subject*: [mg106988] Re: looping*From*: Richard Fateman <fateman at cs.berkeley.edu>*Date*: Sat, 30 Jan 2010 07:14:20 -0500 (EST)*References*: <201001210955.EAA16523@smc.vnet.net> <201001251008.FAA09381@smc.vnet.net> <hjmjja$g0$1@smc.vnet.net> <hjp7ng$d55$1@smc.vnet.net> <hjul7k$s3u$1@smc.vnet.net>

David Bailey wrote: ... > > To describe the Module mechanism as 'flawed' because you can't use it in > this way, seems totally unreasonable - akin to describing real > arithmetic as 'flawed' because it can't represent Sqrt[-1]! Except that other programming languages provide the same facility (lexical scope) while not having the same problem. That is, there is the ordinary way of implementing lexical scope, not the Mathematica way. > > One of the nice features of Module, is that the method of localising > names is totally explicit - so that it is easy to work out what is going > on is subtle cases. Mathematica's implementation is, I think, based on someone's reading of an explanation of lexical scope. Perhaps, "You can think of L.S. as a kind of renaming". But without reading the next sentence, which might be "but of course it is not implemented that way". I agree with your statement -- that looking at the strange renaming it is possible to explain some phenomena that you might find puzzling. But so many things having to do with scope in Mathematica are, at some level, potentially puzzling, that this is a drop in the bucket. E.g. when do names get bound during pattern matching? What is the real value of something which is evaluated any number of times until it has no remaining names, so that x=x+1 assigned to x, 255+Hold[1+x], etc. And proper lexical scope implementation is not so hard, I think. Even given Mathematica semantics. RJF

**References**:**looping***From:*glenn kuhaneck <mcguyver128@yahoo.com>

**Re: Re: looping***From:*Leonid Shifrin <lshifr@gmail.com>