Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5274 > unrolled thread
| Started by | lagj <jean.lagarde@gmail.com> |
|---|---|
| First post | 2011-09-29 06:08 +0000 |
| Last post | 2011-09-30 08:03 +0000 |
| Articles | 2 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Order of evaluations in the Kernel, especially related to CellEpilog lagj <jean.lagarde@gmail.com> - 2011-09-29 06:08 +0000
Re: Order of evaluations in the Kernel, especially related to CellEpilog lagj <jean.lagarde@gmail.com> - 2011-09-30 08:03 +0000
| From | lagj <jean.lagarde@gmail.com> |
|---|---|
| Date | 2011-09-29 06:08 +0000 |
| Subject | Order of evaluations in the Kernel, especially related to CellEpilog |
| Message-ID | <j6121p$m26$1@smc.vnet.net> |
I'm a bit confused as to the order in which Mathematica queues evaluations in
the kernel. I have created a new style of input cell with a CellEpilog
that moves any output (Output or Print type) to a different notebook.
This works fine when I evaluate cells one at a time, but if I evaluate
a group containing many of these cells, my CellEpilog seems not to run
on most of them, and for those cells for which it runs, the order can
be different in the second notebook (e.g. if I'm evaluating a group
containing cell1, cell2, cell3 in that order in the "input" notebook,
the results may appear in the order out1, out3, out2 in the "output"
notebook). I assumed that the CellEpilog runs immediately after the
cell is evaluated, but Mathematica seems to be shuffling things around, i.e.
queuing the CellEpilogs to run together after the main evaluations or
something like that.As for those cells for which the epilog doesn't
seem to run, I suspect it does run, but by running out of order the
selection might be at an unexpected place in the source notebook and
so my code doesn't find any Output or Print cell to process and does
nothing.
Any insight appreciated. My CellEpilog code below.
At a higher level, maybe someone can suggest a better idea to achieve
what I want? I want the option to output the result of some
evaluations to a different notebook (without having to copy them
manually). I prefer the source document to be a notebook and not an m
file because I want to preserve other output in the source notebook
and want the richness of a notebook document for my source.
(outnb points to the desired output notebook)
Block[{cellData,cellDataList},
SelectionMove[EvaluationNotebook[], Previous, Cell];
cellData=NotebookRead[EvaluationNotebook[]];
Which[Part[cellData,
2]=="Output",NotebookWrite[outnb,cellData];
NotebookDelete[EvaluationNotebook[]],
Part[cellData,2]=="Print",cellDataList={cellData};
NotebookDelete[EvaluationNotebook[]];
While[True,
SelectionMove[EvaluationNotebook[],Previous,Cell];
cellData=NotebookRead[EvaluationNotebook[]];
If[Part[cellData,2]=="Print",PrependTo[cellDataList,cellData];
NotebookDelete[EvaluationNotebook[]],
Break[]]];
Map[NotebookWrite[outnb,#]&,cellDataList];
Null]]
[toc] | [next] | [standalone]
| From | lagj <jean.lagarde@gmail.com> |
|---|---|
| Date | 2011-09-30 08:03 +0000 |
| Message-ID | <j63t43$6d9$1@smc.vnet.net> |
| In reply to | #5274 |
Never mind, I should have realized it was the selection moving around.
I modified my epilog to use the EvaluationCell instead of the current
Cell and everything works as expected now.
On Sep 28, 11:08 pm, lagj <jean.laga...@gmail.com> wrote:
> I'm a bit confused as to the order in which Mathematica queues evaluations in
> the kernel. I have created a new style of input cell with a CellEpilog
> that moves any output (Output or Print type) to a different notebook.
> This works fine when I evaluate cells one at a time, but if I evaluate
> a group containing many of these cells, my CellEpilog seems not to run
> on most of them, and for those cells for which it runs, the order can
> be different in the second notebook (e.g. if I'm evaluating a group
> containing cell1, cell2, cell3 in that order in the "input" notebook,
> the results may appear in the order out1, out3, out2 in the "output"
> notebook). I assumed that the CellEpilog runs immediately after the
> cell is evaluated, but Mathematica seems to be shuffling things around, i.e.
> queuing the CellEpilogs to run together after the main evaluations or
> something like that.As for those cells for which the epilog doesn't
> seem to run, I suspect it does run, but by running out of order the
> selection might be at an unexpected place in the source notebook and
> so my code doesn't find any Output or Print cell to process and does
> nothing.
>
> Any insight appreciated. My CellEpilog code below.
>
> At a higher level, maybe someone can suggest a better idea to achieve
> what I want? I want the option to output the result of some
> evaluations to a different notebook (without having to copy them
> manually). I prefer the source document to be a notebook and not an m
> file because I want to preserve other output in the source notebook
> and want the richness of a notebook document for my source.
>
> (outnb points to the desired output notebook)
>
> Block[{cellData,cellDataList},
> SelectionMove[EvaluationNotebook[], Previous, Cell];
> cellData=NotebookRead[EvaluationNotebook[]];
> Which[Part[cellData,
> 2]=="Output",NotebookWrite[outnb,cellData];
>
> NotebookDelete[EvaluationNotebook[]],
> Part[cellData,2]=="Print",cell=
DataList={cellData};
>
> NotebookDelete[EvaluationNotebook[]];
> =
While[True,
>
> SelectionMove[EvaluationNotebook[],Previous,Cell];
>
> cellData=NotebookRead[EvaluationNotebook[]];
>
> If[Part[cellData,2]=="Print",PrependTo[cellDataList,cellData];
>
> NotebookDelete[EvaluationNotebook[]],
>
> Break[]]];
>
> Map[NotebookWrite[outnb,#]&,cellDataList];
>
Null]]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web