MathGroup Archive 2010

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

Search the Archive

Re: Re: Localize Pattern variables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107230] Re: [mg107173] Re: Localize Pattern variables
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Sat, 6 Feb 2010 03:23:43 -0500 (EST)
  • References: <hkeb04$t7v$1@smc.vnet.net> <4B6AB3AA.1080805@gmail.com> <201002050818.DAA06436@smc.vnet.net>

Szabolcs Horvát wrote:
> [...]
> Regarding Module:
> 
> The fact that the following code produces 2 (and not x+1) is rather
> confusing in my opinion, and I do not quite understand why it happens.
> 
> r = 1
> Module[{r},
>  x /. r_ -> r + 1
> ]
> 
> Rule[] somehow interferes with Module's renaming scheme...  If this is
> indeed the intentional behaviour, and not a bug, then I think being
> familiar with it is way beyond what can be expected from most users
> ...  I was aware that Rule can affect scoping, but thinking back, I
> have used code like the one above several times in the past, without
> knowing that it was prone to being broken by setting values to global
> variables ...  At least the front end should colour that 'r' in red
> (which indicates a conflict), not turquoise (which indicates
> localization).

You might find this even more amusing. Or less, depending upon your take 
on such things.

In[35]:= r = 1;
Module[{r, s}, x /. r_ -> r + s /. s -> 2]

Out[36]= 2 + x

One of my February goals is to better understand the byzantine innards 
of Mathematica's lexical scoping inflamation, err, implementation. Alas, 
that was also one of my January goals...

Daniel Lichtblau
Wolfram Research




  • Prev by Date: Re: Could you prove this proposition:the i-th prime gap
  • Next by Date: A New Scientist article verified with Mathematica
  • Previous by thread: Re: Localize Pattern variables
  • Next by thread: Covariant derivatives of tensors?