MathGroup Archive 2008

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

Search the Archive

Re: Re: Module Behavior

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84677] Re: [mg84671] Re: Module Behavior
  • From: "Marcelo Mayall" <mmayall at bol.com.br>
  • Date: Wed, 9 Jan 2008 03:48:49 -0500 (EST)
  • References: <flvcpr$49b$1@smc.vnet.net> <200801081146.GAA07673@smc.vnet.net>

Thanks Jens,

Unfortunately in my case it is not really an advantage using the way you
propose:
Module[{a, b}, a = b; b = 1; Evaluate[a]]

I am really interesting in using "b[1]". I've also tried:
Module[{a, b}, a = b[1]; b[1] = 1; Evaluate[a]]

But still the global b$* persists.

One way I found to avoid this is:
Module[{a, b}, a = b[1]; b[1] = 1; a = b[1];]

But I do not think that the extra set "a=b[1]" is an elegant solution.
Probably there is a better way to solve this.


Regards,
Marcelo Mayall


----- Original Message ----- 
From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
To: <mathgroup at smc.vnet.net>
Sent: Tuesday, January 08, 2008 9:46 AM
Subject: [mg84677] [mg84671] Re: Module Behavior


> Hi,
>
> no, because the b$* are only removed when no expression
> in your session include the local generated variables
> If you change your Module to
>
> Module[{a, b}, b[1] = 1; a = b[1];]
>
> everything is fine, but with your definition
> a is not evaluated again and so it will hold
> a reference to the local defined variable b.
> If you like you can resolve this by
>
> Module[{a, b}, a = b; b = 1; Evaluate[a]]
>
> and you will see that the global $b* are gone ..
>
> Regards
>   Jens
>
> 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"}}
>>
>> 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: Mathematica 6.0.1: problems with Beta Negative Binomial
  • Next by Date: Re: Module Behavior
  • Previous by thread: Re: Module Behavior
  • Next by thread: Re: Module Behavior