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


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

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

From Szabolcs Horvát <szhorvat@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject When exactly is an Initialization (for Dynamic, Module, etc.) evaluated?
Date 2011-10-29 11:17 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j8gnbd$5db$1@smc.vnet.net> (permalink)

Show all headers | View raw


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?

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web