Message Boards Message Boards

0
|
5078 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

How does Mathematica evaluate a notebook?

Posted 11 years ago
During the handling of Notebook, I came across the problem that some parts of the code evaluates the FrontEnd. I got into a situation that the kernel did not know what the FrontEnd did in the same Cell. I would like to ask if anyone knows about literature or other sources that describe how to do Notebook evaluation in Mathematica?

Thanks for any help!
POSTED BY: Mirek M
4 Replies
Posted 11 years ago
I understand your interpretation.

However, I do not understand why the code is not evaluated sequentially in the Kernel. (It is not Dynamics function.)
If the kernel evaluated everything, so it was not a problem with results.

My current idea is:
Evaluation order is changed or some code is not evaluated by kernel. I mean that each Mathematica cell has something like this: pre-processing, processing, post-processing.
My explanation is just speculation.

Thank you for your interpretation.
POSTED BY: Mirek M
Thank you for the clairifcation.

I think that the behavior that you are observing is because when both commands
SetOptions[EvaluationNotebook[], CellContext -> "$Mi`"];
Context[]
are in the same Cell think about the sequence of events that occur.

When the cell is executed, it's CellContext is Global`.  The expression is then sent off to the Kernel to be evaluated in the Global` context. The first command is then evaluated which changes the CellContext Option for the notebook (which will take effect for the next command that is sent to the Kernel).  However the Kernel still has the Context[] command to evaluate, still in teh Global` context, which it does and returns the result to the notebook.
POSTED BY: David Reiss
Posted 11 years ago
Thanks for the answer to the question.

Cell1:
SetOptions[EvaluationNotebook[], CellContext -> "Global`"];
Cell2:
SetOptions[EvaluationNotebook[],
CellContext ->
  "$Mi`"]; (* set up a new context for the current notebook *)
Context[] (* try to print out the context, if the newly-defined \
context can be realized by the front-end then the output should have \
been $Mi', which is not the case here *)
There must be cell divided.
Cell3:
Context[]

You can write why I use SetOptions becuse there is command Begin["$Mi`"]. Answer is that I can not use "Begin" because I manipulate contexts across the different notebook files.

Thanks again.
POSTED BY: Mirek M
Could you give a simple example of what you are encountering?
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract