| Author |
Comment/Response |
Michael
|
02/24/09 12:19pm
How can I change context inside a function? For example:
MyContext`X = 1;
X = 10;
f[] := (
$ContextPath = Prepend[$ContextPath, "MyContext`"];
Print[$ContextPath];
Print[X, ", ", MyContext`X];
$ContextPath = Delete[$ContextPath, 1];
);
f[];
It gives me:
{MyContext`,PacletManager`,WebServices`,System`,Global`}
10, 1
But that is wrong! Inside the function f, the $ContextPath has "MyContext`" in the first place. Therefore both variables X and MyContext`X belong to the context "MyContext`" and should be equal to 1, but Mathematica says that they are different...
URL: , |
|