1
$\begingroup$

Mathematica is using definitions from other open files in the same folder.

I want variables not defined in a particular file to be treated as undefined variables. I do not want Mathematica to pick the expression of these variables from other files. Is there any way to go about this?

$\endgroup$
4
  • 1
    $\begingroup$ Maybe run Exit[] in your current notebook before you execute anything else in it? That should unload all the definitions. $\endgroup$ Commented Jun 28, 2018 at 7:42
  • $\begingroup$ @Shredderroy That works. Thanks! $\endgroup$
    – cord
    Commented Jun 28, 2018 at 7:47
  • $\begingroup$ Have a look to this question, you can also set a context "unique to this Notebook" $\endgroup$
    – rhermans
    Commented Jun 28, 2018 at 7:49
  • $\begingroup$ @rhermans Thanks for the second link. Changing the global policy for CellContext to "Notebook" does exactly what I was looking for. $\endgroup$
    – cord
    Commented Jun 28, 2018 at 7:56

1 Answer 1

4
$\begingroup$

Set the option value for CellContext to Notebook:

SetOptions[EvaluationNotebook[], CellContext -> Notebook]

Use $FrontEndSession (respectively, $FrontEnd) in place of EvaluationNotebook[] for the option setting to apply to all the notebooks in the current session (respectively, to all notebooks globally).

enter image description here

$\endgroup$
1
  • $\begingroup$ This works, but changing the default global policy for CellContext was more convenient for me. Link for future reference $\endgroup$
    – cord
    Commented Jun 28, 2018 at 8:00

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.