MathGroup Archive 2008

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

Search the Archive

Re: about scoping in modules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85777] Re: [mg85769] about scoping in modules
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Fri, 22 Feb 2008 04:58:16 -0500 (EST)
  • References: <200802212305.SAA18458@smc.vnet.net>

On Feb 21, 2008, at 6:05 PM, P_ter wrote:

> Hello,
> 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?

The simple answer is because Module creates a variable named  
global2mfb$n (where n is an integer) and mfb is looking for a  
variable named global2mfb.

> 2. how can I realize what I want?

I'm not clear on what you want.  If you want to use global2mfb in mfb  
just pass it in, and return it's new value from mfa and assign that  
back into global2mfb in mfa.  But really mfb seems unnecessary.

Regards,

Sseziwa


  • Prev by Date: Re: Inset headache
  • Next by Date: Re: about scoping in modules
  • Previous by thread: about scoping in modules
  • Next by thread: Re: about scoping in modules