Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Q: scoping of variables in rules' topicStudent Support Forum > General > "Q: scoping of variables in rules"

Next Comment >Help | Reply To Topic
Author Comment/Response
J. Herrera
11/28/99 08:35am

When I input this in Mathematica version 3

   foo=bar[k_]->k;
   Do[Print[bar[1]/.foo],{k,3}]

I get the output

   1
   2
   3

Instead of just 1's. It looks like the iterator modifies the rule in each pass. But page 365 in the Mathematica Book says that variables in rules
are treated as local, regardless of other scoping constructs (and without an explicit Module or Block statement). Also, I've tried wrapping
my rule in Block/Module, and it's no use. What am I missing here? How can I rewrite this so that the iterator doesn't modify my rule?


Thanks in advance,

J. Herrera

URL: ,

Subject (listing for 'Q: scoping of variables in rules')
Author Date Posted
Q: scoping of variables in rules J. Herrera 11/28/99 08:35am
Re: Q: scoping of variables in rules Aaron Honecker 11/30/99 3:39pm
Next Comment >Help | Reply To Topic