Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5986 > unrolled thread

When exactly is an Initialization (for Dynamic, Module, etc.) evaluated?

Started bySzabolcs Horvát <szhorvat@gmail.com>
First post2011-10-29 11:17 +0000
Last post2011-10-29 11:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  When exactly is an Initialization (for Dynamic, Module, etc.) evaluated? Szabolcs Horvát <szhorvat@gmail.com> - 2011-10-29 11:17 +0000

#5986 — When exactly is an Initialization (for Dynamic, Module, etc.) evaluated?

FromSzabolcs Horvát <szhorvat@gmail.com>
Date2011-10-29 11:17 +0000
SubjectWhen exactly is an Initialization (for Dynamic, Module, etc.) evaluated?
Message-ID<j8gnbd$5db$1@smc.vnet.net>
Dear all,

Dynamics/Module/etc. have an Initialization option, which, according to 
the documentation, is evaluated the first time the Dynamic cell becomes 
visible.

Is this the only instance the Initialization is evaluated?  Should it be 
the case that in a kernel session, an Initialization will not be 
evaluated more than once?

Take this example:

Create a cell using

Dynamic[counter,
  Initialization :> (If[! ValueQ[counter], counter = 0, counter++];
    Print["init ", counter])]

It will show 0.

Now quit the kernel, and wait a couple of seconds.  Move the text input 
cursor close to the cell.  The kernel will re-launch, and the 
Initialization will be evaluated.  Now resize the window a bit.  The 
Initialization will be re-evaluated and the counter will show 1.

Is this the intended behaviour or a bug?  Generally, when is an 
Initialization evaluated?  Can I count on it not being evaluated more 
than once in a session?

Suppose that we have a Dynamic cell which actually acts as a counter of 
some type of event, and is initialized to 0 in the Initialization 
option.  Can it happen that it will randomly get re-initialized because 
of some UI events?

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web