MathGroup Archive 2008

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

Search the Archive

Re: Module Behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84676] Re: [mg84660] Module Behavior
  • From: "Marcelo Mayall" <mmayall at bol.com.br>
  • Date: Wed, 9 Jan 2008 03:48:17 -0500 (EST)
  • References: <200801080837.DAA04375@smc.vnet.net> <47838F28.3030702@wolfram.com>

Thanks Carl,

Still it is not clear for me what is going on.

You wrote that if the temporary variable has only OwnValues definitions, it
is removed at the end of the Module. Ok, the following example is in
agreement with this statement:

In[1]:= Module[{a}, a = 1; Print[OwnValues[a]]]
During evaluation of In[1]:= {HoldPattern[a$64] :> 1}
In[2]:= Names["a$*"]
Out[2]= {}

You also wrote that if the temporary variable has any DownValues definition,
the variable persists. But in the following case, the variable "a" has a
DownValues definition and did not persist.

In[3]:= Module[{a}, a[1] = 1; Print[DownValues[a]];]
During evaluation of In[3]:= {HoldPattern[a$74[1]] :> 1}
In[4]:= Names["a$*"]
Out[4]= {}


Regards,
Marcelo Mayall



----- Original Message ----- 
From: "Carl Woll" <carlw at wolfram.com>
To: "Marcelo Mayall" <mmayall at bol.com.br>
Cc: <mathgroup at smc.vnet.net>
Sent: Tuesday, January 08, 2008 12:56 PM
Subject: [mg84676] Re: [mg84660] Module Behavior


> 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
>>
>>
>
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition. Version: 7.5.516 / Virus Database:
> 269.17.13/1213 - Release Date: 1/7/2008 9:14 AM
>
>



  • Prev by Date: Re: Re: Module Behavior
  • Next by Date: Re: Re: Give a list of options in Mathematica 6
  • Previous by thread: Re: Module Behavior
  • Next by thread: Re: Module Behavior