- To: mathgroup at smc.vnet.net
- Subject: [mg106998] Re: looping
- From: Noqsi <jpd at noqsi.com>
- Date: Sun, 31 Jan 2010 05:56:42 -0500 (EST)
- References: <201001210955.EAA16523@smc.vnet.net> <201001251008.FAA09381@smc.vnet.net>
On Jan 30, 5:13 am, Richard Fateman <fate... at cs.berkeley.edu> wrote: > 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. You like to "strain out gnats and swallow camels", don't you? Any mechanism can be abused. In this case, inadvertent abuse seems very unlikely, while Leonid has demonstrated productive use (very cool). Therefore, the implementation your ideology demands would have a real problem. > That is, there is > the ordinary way of implementing lexical scope, not the Mathematica way. So? Mathematica does it better, enabling you to single out little bits of the state and make them persistent. It's much like the "continuations" of other languages, except it's: 1. Better targeted. 2. More transparent. Continuations are an obfuscated, undisciplined, "shotgun" mechanism compared to what Mathematica offers here (yes, I know, they are beloved by CS sacerdotes). > > > > > 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". It doesn't match your ideology. I doubt many Mathematica users share that ideology. > > I agree with your statement -- that looking at the strange renaming it > is possible to explain some phenomena that you might find puzzling. It's only strange because it doesn't match your ideology. > 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. What you call proper I call less capable. I may be using Leonid's techniques in the future.