MathGroup Archive 2008

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

Search the Archive

Re: Module Behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84680] Re: [mg84660] Module Behavior
  • From: Carl Woll <carlw at wolfram.com>
  • Date: Wed, 9 Jan 2008 03:50:23 -0500 (EST)
  • References: <200801080837.DAA04375@smc.vnet.net>

Marcelo Mayall wrote:

>One of the main features of the function Module is that you can specify 
>symbols to be treated as local. For example:
>
>In[1]:=   Module[{a, b}, a = b; b = 1;]
>In[2]:=   {Names["a$*"], Names["b$*"]}
>
>Out[2]= {{}, {}}
>
>However, if we change the local symbol "b" to "b[1]" it does not treat 
>as local anymore.
>
>In[3]:=  Module[{a, b}, a = b[1]; b[1] = 1;]
>In[4]:=  {Names["a$*"], Names["b$*"]}
>
>Out[4]= {{}, {"b$69"}}
>  
>
The difference here is that you are giving a an own value, while you are 
giving b a down value. If a Temporary variable has only OwnValues 
definitions, it is removed at the end of a Module. If a Temporary 
variable has any DownValues definitions, the variable persists.

Carl Woll
Wolfram Research

>And each time you execute this command line a new variable "b$*" will be 
>created. 
>
>In[14]:= Module[{a, b}, a = b[1]; b[1] = 1;]
>In[15]:= {Names["a$*"], Names["b$*"]}
>
>Out[15]= {{}, {"b$69", "b$77", "b$79", "b$81", "b$84", "b$86", "b$88", 
>"b$90", "b$92", "b$94"}}
>
>
>Shouldn't the function Module treat the symbol "b[1]" as local too?
>Is this an expected or unexpected result?
>
>Regards,
>Marcelo Mayall
>
>  
>



  • Prev by Date: Re: Re: Locator 3D
  • Next by Date: Re: Mathematica 6.0.1: problems with Beta Negative Binomial
  • Previous by thread: Module Behavior
  • Next by thread: Re: Module Behavior