Let's create two notebooks external.nb and primary.nb. Then call the external.nb notebook from the primary.nb and investigate values of Out[ ]. The context of the external notebook is not important, however for the demonstration of the strange behavior it should contain number of cells. My external.nb notebook contains 4 cells:
a=1;
b=1
c=1
d
The primary notebook contains the single cell which calls the external notebook from the primary. If we put both notebooks in the same directory, the cell is
NotebookEvaluate @ FileNameJoin[
{ NotebookDirectory[EvaluationNotebook[]], "external.nb"}
]
Open the primary.nb and evaluate the cell which calls the evaluation of the external.nb.
The output yields
Out[1] = d
So it returns output of the last cell of the called notebook.
Now refer to input %4
of primary.nb. I would expect an empty output, since at the moment there is no %4
out in the primary notebook. However the result is the same d
.
Asking
?? Out[]
we see the primary.nb knows all Out[]
values of the external.nb notebook. Bug or feature?
primary.nb
keeps counting up from 1, yet higher input line values are already set inOut
thanks toexternal.nb
. It is indeed strange. $\endgroup$ – Szabolcs Mar 19 '19 at 12:22