Re: can one make local symbol in a pure function?

*To*: mathgroup at smc.vnet.net*Subject*: [mg127407] Re: can one make local symbol in a pure function?*From*: "Nasser M. Abbasi" <nma at 12000.org>*Date*: Sun, 22 Jul 2012 04:34:06 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@smc.vnet.net*References*: <jud8n8$j33$1@smc.vnet.net>*Reply-to*: nma at 12000.org

On 7/20/2012 10:46 PM, Bill Rowe wrote: > > This makes it sound like you want to have a local variable in > your function that does not create a new global symbol. Yes, of course. I simply wanted to localize everything at the point where I wanted to use it. Did not want make a separate Module. If this > is your goal, you should be aware Module does not do this. If > you start a fresh session and do > > ?Global`* > f[x_]:=Module[{a=2},x^a] > f[Range@3]; > ?Global`* > > you will find that new symbols a, a$ appear in the Global > context. They simply don't have values in the Global context > I think this is terrible. Why does this happen? It makes no sense to me. A local symbol should not move to the global name space. You did not even need to make a call. Just the definition itself was enough: ------------------------- Remove["Global`*"] f[x_]:=Module[{a=2},x^a] ?Global`* a a$ f x ---------------------- For me, I would have expected to see ONLY 'f' here in the global name space. Everything else would be contained inside the module namespace. i.e. can be seen inside the Module. 'x' above is a parameter name (ok pattern name in Mathematica), but from programming point of view, it is a formal parameter. Why would the name of a formal parameter suddenly become global just by defining a function? Why does Mathematica do this? It seems it should be possible to easily fix this. Simply do not put these symbols into the global name space table when reading the Module. Why is this hard to do? Will fixing break things? Any one depending on the local names defined inside a module be also a global symbol should not doing that to start with as it is against everything we learned about programming in school. The evaluator knows it is reading a Module. Hence make a symbol table for this Module only. It would have been less bad if it added things like f f`a$ f`x$ or such, to the global name space. At least this avoids a clash with the global namespace. I like Mathematica, and it is really a nice system to try things with it and explore mathematics quickly, but issues things like the above makes it very hard to write very large applications with it. The above for me is even worst than using GOTO. thanks, --Nasser