I thought when we type a symbol without specifying its Context, it will search all the Context in $ContextPath for existing symbol.
But in Module/Block, or even CompoundExpression, all the symbols will be converted to Global Context regardless of the content of $ContextPath.
Unfortunately, I didn't find any information in the documentation explaining this behavior.Is it a feature? What is purpose of this design?
Here is my example:
Code Here:
AppendTo[$ContextPath, "w`"];
w`ww = 1;
Context[ww]
Similar behaviour can be observed as follows:
Quiet@Remove["A`x", "B`x", "Global`x"];
{A`x, B`x} = {"a", "b"};
$Context = "A`";
Print@x;
$Context = "B`";
Print@x;
$Context = "Global`";
gives a, b, but
(
Quiet@Remove["A`x", "B`x", "Global`x"];
{A`x, B`x} = {"a", "b"};
$Context = "A`";
Print@x;
$Context = "B`";
Print@x;
$Context = "Global`";
)
gives Removed[x] twice.




$ContextPathaffects parsing, not evaluation. Because of the parentheses,(AppendTo[$ContextPath, "w`"]; w`ww = 1; Context[ww])is parsed in its entirety first, and evaluation begins only afterwards. Before the first part of this is evaluated,$ContextPathisn't changed yet. – Szabolcs May 30 '16 at 16:45Contextto symbols first, which is not in http://reference.wolfram.com/language/tutorial/Evaluation.html. Is the parsing step executed before the whole evaluation? – vapor May 30 '16 at 16:51x, it immediately needs to decide whether this refers toa`xorb`xor something else. Evaluation can only start after a full expression is read it. When you add parentheses, you make those separate lines into a single expression. – Szabolcs May 30 '16 at 17:16ToExpressionto try to falsify this hypothesis and gain more confidence. This behaviour was discussed on this site multiple times, but I was too lazy to find it. I assumed Kuba's link pointed to one. – Szabolcs May 30 '16 at 17:18