Re: Do Modules Produce Side Effects?
- To: mathgroup at smc.vnet.net
- Subject: [mg47986] Re: [mg47964] Do Modules Produce Side Effects?
- From: "J. McKenzie Alexander" <jalex at lse.ac.uk>
- Date: Tue, 4 May 2004 07:03:18 -0400 (EDT)
- References: <200405040508.BAA17753@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
> The MathBook definition of Module tells me, "Module creates new > symbols to represent each of its local variables every time it is > called." This is true. But ask yourself, how does Module know what variables are to be considered local and what variables are global? Quite often one will want to mix local and global variables in the same module. Hence, Module will treat as local only those variables named in the first list. If a variable is not listed there, it is assumed to be a global variable. In your example, you did not tell Module to treat 'm' as a local variable. In[1]:= m=i^2 Out[1]= i^2 In[2]:= Module[{m},m=4;2*m] Out[2]= 8 In[3]:= m Out[3]= i^2 > I am led by this, and other Module descriptions, to conclude > Modules do not produce side effects, like Blocks do. Modules can produce side effects as well. It entirely depends on whether one uses global variables inside the module in addition to local variables. Jason -- Dr J. McKenzie Alexander Department of Philosophy, Logic and Scientific Method London School of Economics and Political Science Houghton Street, London WC2A 2AE
- References:
- Do Modules Produce Side Effects?
- From: Harold.Noffke@wpafb.af.mil (Harold Noffke)
- Do Modules Produce Side Effects?