Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Do Modules Produce Side Effects?

  • To: mathgroup at
  • Subject: [mg47984] Re: [mg47964] Do Modules Produce Side Effects?
  • From: Andrzej Kozlowski <akoz at>
  • Date: Tue, 4 May 2004 07:03:16 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

On 4 May 2004, at 14:08, Harold Noffke wrote:

> $Version "5.0 for Microsoft Windows [2000] (November 18, 2003)"
> MathGroup:
> The MathBook definition of Module tells me, "Module creates new
> symbols to represent each of its local variables every time it is
> called."  I am led by this, and other Module descriptions, to conclude
> Modules do not produce side effects, like Blocks do.  However, we have
> ...
> In[1]:= m=i^2
> Out[1]= i^2
> In[2]:= Module[ {}, m=4; 2*m ]
> Out[2]= 8
> In[3]:= m
> Out[3]= 4
> I expected m to remain unchanged from its original i^2.  But Module
> changed m to 4, just as I would expect a Block to do.
> Am I misunderstanding something about the "side effect safety" of
> Modules?
> Regards,
> Harold
Since you did not localize m by including it in curly brackets it 
remained a global variable. This is in no sense  a "side effect" but 
just the standard distinction between "local" and "global".

Andrzej Kozlowski
Chiba, Japan

  • Prev by Date: Re: Re: bug in IntegerPart ?
  • Next by Date: Re: Do Modules Produce Side Effects?
  • Previous by thread: Do Modules Produce Side Effects?
  • Next by thread: Re: Do Modules Produce Side Effects?