4
$\begingroup$

hello.nb

SetOptions[EvaluationNotebook[], CellContext -> Notebook]

Print["hello"];

a = 1;
Print[a];

Print@Context[]

bye.nb

SetOptions[EvaluationNotebook[], CellContext -> Notebook]

Print["bye"];

Print[a];

Print@Context[]

Wolfram Script

#!/usr/bin/env wolframscript
(* ::Package:: *)

UsingFrontEnd[
  Map[
   NotebookEvaluate@FileNameJoin[{$UserDocumentsDirectory, #}] &,
   {"hello.nb", "bye.nb"}
   ]
  ];

Quit[]

enter image description here

enter image description here

$\endgroup$
11
  • $\begingroup$ Ummm.... what's your question? $\endgroup$ Commented May 18, 2019 at 6:09
  • $\begingroup$ This is a bug or a feature? Perhaps I misunderstand how UsingFrontEnd works. Is there a workaround? $\endgroup$ Commented May 18, 2019 at 6:58
  • $\begingroup$ @AlexeyGolyshev it seems like they did what you told them to do. Try it in the other order? $\endgroup$ Commented May 18, 2019 at 7:13
  • $\begingroup$ @CATrevillian I am not sure that I fully understand your idea... $\endgroup$ Commented May 18, 2019 at 7:31
  • $\begingroup$ Did you try using math -script instead of wolframscript? (Just curious if it makes a difference) $\endgroup$
    – Szabolcs
    Commented May 18, 2019 at 7:37

1 Answer 1

1
$\begingroup$

WORKAROUND

$Context instead of SetOptions[EvaluationNotebook[], CellContext -> Notebook]

hello.nb

$Context = "H`"

Print["hello"];

a = 1;
Print[a];

Print@Context[]

bye.nb

$Context = "B`"

Print["bye"];

Print[a];

Print@Context[]

enter image description here

$\endgroup$
2
  • $\begingroup$ Hah! I knew at least most of half of what I was talking about, great implementation! Do you have any issue with the printing of the context occurring? Any idea how to eliminate that? $\endgroup$ Commented May 18, 2019 at 20:33
  • $\begingroup$ @CATrevillian Thank you very much! You and @Szabolcs helped me a lot. I was understanding that the problem was in context, but it did not occur to me to see the context, because I thought it was unique. By the way, I reported this problem to the Wolfram Support. I will add the bugs tag when they confirm this. $\endgroup$ Commented May 19, 2019 at 6:25

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.