MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: What is the point of having Initializations in DynamicModule and Manipulate?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123279] Re: What is the point of having Initializations in DynamicModule and Manipulate?
  • From: John Fultz <jfultz at wolfram.com>
  • Date: Wed, 30 Nov 2011 03:20:28 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Reply-to: jfultz at wolfram.com

On Tue, 29 Nov 2011 07:03:03 -0500 (EST), Chris Degnen wrote:
> The following is somewhat tangential to the initial question:
>
> John Fultz wrote:
>
>> Question...what do I do if I want thing A to evaluate before
>> thing B?  Why, of course, use any number of Mathematica
>> paradigms for sequential evaluation. The semicolon, representing
>> CompoundExpression, for example.  No need to invent anything here.
>>
>> Further question...what if I want thing A to evaluate before
>> thing B, but thing B is part of a dynamic interface.  This is
>> the interesting question.  There are absolutely no guarantees
>> about the order in which two discrete Dynamics will evaluate,
>> so I can't set up multiple Dynamics in a row to evaluate in
>> sequence.  I could nest Dynamics (outer ones always evaluate
>> before inner ones), but then I may have to play some tricky
>> games with Refresh to prevent code from evaluating which
>> should only ever evaluate once.
>>
>
> Sal Mangano wrote about this issue in The Mathematica Cookbook,
> starting at page 613:
>
> "as explained by Theodore Gray ... using DynamicWrapper will
> always guarantee that the second argument of DynamicWrapper will
> be computed before any dynamic expressions contained in the
> first argument."
>
> In effect it appears to be similar to nesting Dynamics, at least
> in one respect; and is unlike Initialize in that the second argument
> is dynamically updated.
>
> An example is given:
>
> http://demonstrations.wolfram.com/2DCellularAutomatonAnimations/
>
> where nested DynamicWrappers are used.
>
> Documentation for DynamicWrapper only appeared in version 8
> although the functionality exists in versions 6 and 7.

Yes, all of this is exactly true and well-stated, although I'll use my own 
prerogative to add more clarification :).  DynamicWrapper and Initialization are similar (although I never really thought of it this way) in that they are both computations initiated by the FE whose results do not display.  The difference is that the Initialization option should be used for code you want to be evaluated exactly once (per on-screen instance), whereas code which should be re-evaluated when dependent variables are updated should be part of 
DynamicWrapper.  Each behavior is independently useful.

Sincerely,

John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.



  • Prev by Date: Point light source demo
  • Next by Date: Re: Ragged region boundary
  • Previous by thread: Re: What is the point of having Initializations in DynamicModule and Manipulate?
  • Next by thread: Timing graphics in the real world