Re: A kernel, multiple notebooks, and Global?
- To: mathgroup at smc.vnet.net
- Subject: [mg87730] Re: [mg87663] A kernel, multiple notebooks, and Global?
- From: John Fultz <jfultz at wolfram.com>
- Date: Wed, 16 Apr 2008 05:04:19 -0400 (EDT)
- Reply-to: jfultz at wolfram.com
Actually, the kernel has absolutely no knowledge of which notebooks produce a particular evaluation. Even though there are functions which can query this information, such as EvaluationNotebook and ButtonNotebook, these functions are resolved by having the kernel ask the front end for the information. And the kernel will never request the information unless you've explicitly asked it to. The only down sides I can think of for using Mathematica in the way you're describing are the potential confusion it would cause you with very complex usage, and the potential difficulty in recreating a sequence of evaluations in alater session. If you feel you can confidently avoid these pratfalls, then by all means, do it! I should point out here that, for those who *don't* wish to see interactions between notebooks, there's a new feature in version 6 to support this. In the Evaluation menu, there's a new submenu called "Notebook's Evaluation Context". This allows you to set rules for what context to use in a given notebook. You can specify a specific context, request a context which is guaranteed unique to that notebook, or request that each cell group in a notebook get its own context. The feature also keeps track of $Line separately for each context (even here, this is all done by the FE...the kernel remains ignorant of anything except the FE's requests to switch $Context, $Line, $ContextPath, etc.). This is, essentially, the same mechanism which is used in the help viewer to ensure unique contexts in each example group of a function home page. Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc. On Tue, 15 Apr 2008 05:51:36 -0400 (EDT), AES wrote: > Pardon any awkward wordings here, but I may not have all the jargon > relevant to my query clearly understood. > > Suppose that on a single-user computer I have several notebooks open > that address different parts of a common calculation, and thus share > overlapping sets of globally used variable names. > > The broad question is then, how far can I go -- or what dangers may lurk > -- in treating these multiple notebooks as essentially one unified > notebook that just happens to be stored in multiple files and appear on > screen in multiple windows? > > 1) For example, in terms of contexts or scopes, I'm guessing that > "Global is Global": the Global` context for all of these notebooks is > set by or recorded by the kernel, and at any one instant is exactly the > same for all these open notebooks -- right? > > 2) Suppose a certain Input cell is present in exactly identical form at > some random (i.e., different) point in each of the notebooks; I've been > executing cells from all of the notebooks in some irregular sequence; > and then I execute this particular cell in whichever of the notebooks > happens to be most convenient for me. > > I assume the kernel is likely to be able to recognize which notebook > submitted these Input instructions. But beyond that, unless this cell > contains some code which directly or indirectly identifies the notebook > in which the cell resides, and uses this information to modify the Input > instructions, executing the copy of this cell that resides in any of the > notebooks will produce exactly the same result, except for where it > displays its output -- right?