MathGroup Archive 2004

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

Search the Archive

RE: Do Modules Produce Side Effects?

  • To: mathgroup at
  • Subject: [mg47995] RE: [mg47964] Do Modules Produce Side Effects?
  • From: "DrBob" <drbob at>
  • Date: Wed, 5 May 2004 08:11:01 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

The first argument of Module is a list of its local variables. If you use a
variable not in that list, you're talking about a variable from the context
outside the Module.


-----Original Message-----
From: Harold Noffke [mailto:Harold.Noffke at] 
To: mathgroup at
Subject: [mg47995] [mg47964] Do Modules Produce Side Effects?

$Version "5.0 for Microsoft Windows [2000] (November 18, 2003)"


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


  • Prev by Date: Re: Working with binaries
  • Next by Date: color in SphericalPlot3D
  • Previous by thread: Re: Do Modules Produce Side Effects?
  • Next by thread: RE: Do Modules Produce Side Effects?