I have some notebooks belonging to a project. I want them to share definitions with each other, but not with other notebooks.
Here is one approach that I thought would accomplish this: go to
Evaluation > Kernel Configuration Options and add a new kernel, say
mykernel. Then in each project notebook execute
SetOptions[EvaluationNotebook, Evaluator -> "mykernel"] to reset the kernel for that notebook.
To my surprise, symbol definitions appear to be shared across kernels. That is, if I have a non-project notebook running (
Evaluation > Notebook's Kernel is
local), it still sees all the defintions in the project notebooks.
I seem to have misunderstood what it means to assign a new kernel, which I though was equivalent to say "run in a separate process". I did not find the documentation helpful in understanding what is going on here. How can I get what I want?
I had closed and restarted Mma once to check on this behavior, and I still got the reported behavior. After Kuba's comments I did so again (as part of a more extensive experiment), and now I cannot replicate the reported behavior. I will edit this question again if I see it again (and would appreciate any confirming reports, especially if the cause is discovered).
Motivation for use of separate kernel: privacy. (I don't want to worry about name clashes.)
Why not use contexts via
Begin? As far as I can tell,
Begin is almost completely unsafe for this purpose. Example:
ClearAll[f, x] Begin["MyContext`"] f[x_] := x^2 + 1 End ?? f
We find the definition apparently inside the block is in fact global (because the symbol
f already existed at the global level).