1
$\begingroup$

Some questions related to $Context and $ContextPath have already been asked and answered, but I still cannot fully grasp the concept. Evaluating

CompoundExpression[Begin["Ctx1`"], x = 1, End[], {Ctx1`x, x}]

in a pristine kernel yields {Ctx1`x, 1}. However, evaluating each level 1 statement in turn in a pristine kernel results in {1, x}. If this behaviour complies with the design, where is it documented?

$\endgroup$
3
  • 1
    $\begingroup$ It must be due to some quirk of the parsing like in this answer mathematica.stackexchange.com/a/598/72682 I'm surprised that printing out the contexts gives the correct printouts but still gets it wrong CompoundExpression[Print[$Context], Begin["Ctx1`"], Print[$Context], x = 1, End[], Print[$Context], {Ctx1`x, x}] $\endgroup$
    – flinty
    Commented Oct 3, 2020 at 22:03
  • 1
    $\begingroup$ It behaves as expected, see also this answer with doc links: mathematica.stackexchange.com/a/119187/5478. @flinty Print and Begin are evaluated after the whole compound expression was parsed so there is no way for Begin to affect parsing of x. $\endgroup$
    – Kuba
    Commented Oct 4, 2020 at 6:41
  • $\begingroup$ @Kuba Many thanks. It really is stated quite clearly in tutorial/ModularityAndTheNamingOfThings#5934 about "Setting Up Wolfram Language Packages". The question is resolved. $\endgroup$ Commented Oct 4, 2020 at 6:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.