Re: Module Behavior
- To: mathgroup at smc.vnet.net
- Subject: [mg84671] Re: Module Behavior
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 8 Jan 2008 06:46:22 -0500 (EST)
- Organization: Uni Leipzig
- References: <flvcpr$49b$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
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
>
>
- Follow-Ups:
- Re: Re: Module Behavior
- From: "Marcelo Mayall" <mmayall@bol.com.br>
- Re: Re: Module Behavior