MathGroup Archive 2008

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

Search the Archive

Re: about scoping in modules

  • To: mathgroup at
  • Subject: [mg85797] Re: about scoping in modules
  • From: Albert Retey <awnl at>
  • Date: Fri, 22 Feb 2008 07:24:35 -0500 (EST)
  • References: <fpkvqk$hrr$>

Hi Peter

> in the next two modules I would like that the inner module uses a variable from the outer module.
> mfb[oneObj_] := Module[{ttmp = oneObj},AppendTo[ global2mfb, ttmp]]
> mfa[e_] := Module[{global2mfb = e, t = 3},mfb[t]  ] 
> mfa[{2,3}] gives a message that global2mfb is not a variable with a value, so it can not be changed.

> It means I do not understand the concept of module in Mathematica. My questions are:
> 1. why does it go wrong?

Because of the difference between lexical and dynamical scoping. This is 
explained in the documentation. In version 6 you can copy the following 
line to the documentation center to point it to a useful starting point 
about the topic:


> 2. how can I realize what I want?

use Block instead of Module in the definition of mfa and it will do what 
I think you try to achieve...



  • Prev by Date: Re: "Assuming"
  • Next by Date: Re: Getting the View I want from ListPlot3D and Show
  • Previous by thread: Re: about scoping in modules
  • Next by thread: Re: about scoping in modules