Module inside Module. Conflict between inner Module local variable with outer module parameter
- To: mathgroup at smc.vnet.net
- Subject: [mg79559] Module inside Module. Conflict between inner Module local variable with outer module parameter
- From: Nasser Abbasi <nma at 12000.org>
- Date: Sun, 29 Jul 2007 00:13:05 -0400 (EDT)
This Mathematica 6.0.1
I just found out that I can't declare a local variable inside a Module
to be the same name as an input parameter for the outer module.
foo[i_] := Module[{},
boo[] := Module[{i = 1},
Print[i];
];
boo[];
]
It seems an inner Module is being treated on the same level as the
outer module as far are variable scope is concerned. When I call
foo[5] for example, the local variable 'i' for boo[] was set to 5,
when it was supposed to be LOCAL to boo[] ! It looks like local
variables to inner modules are treated just like they are local
variables to the outer module.
I understand that one can't make a local variable with the same name
as the argument, but boo[] above is supposed to be a separate module
(even though it is an inner module) except its scope is limited to
inside foo[].
So I do not see why the above would not be allowed. This restriction
does not seem to make too much sense to me.
Is there a trick to make the above legal without moving boo[] outside
of foo[] ?
thanks,
Nasser