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

*To*: mathgroup at smc.vnet.net*Subject*: [mg123035] Re: What is the point of having Initializations in DynamicModule and Manipulate?*From*: John Fultz <jfultz at wolfram.com>*Date*: Mon, 21 Nov 2011 04:27:39 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Reply-to*: jfultz at wolfram.com

On Mon, 21 Nov 2011 15:57:00 +1100, Mike H wrote: > So the output cell containing the list {plot, "Silder", g[0]} is not a > display of the DynamicModule? To refresh, the code you included was... DynamicModule[{c}, {plot, Slider[Dynamic[c]], g[Dynamic@c]}, Initialization :> (g[x_] := Cos[x]; plot = Plot[g[x], {x, 1, 10}]), UntrackedVariables -> {g}] * plot is not in a Dynamic. You get exactly what the Shift+Enter evaluation gave you. * g[] is not in a Dynamic (regardless of what argument you pass it). You get exactly what the Shift+Enter evaluation gave you. The Shift+Enter evaluation has completed long before the DynamicModule is displayed and the Initialization is executed. And the fact that you expected g[Dynamic@c] and/or Cos[Dynamic@c] to return anything sensible (which I had overlooked in your example before) indicates that you are failing to understand some really fundamental stuff about Dynamic. See here: http://forums.wolfram.com/mathgroup/archive/2010/May/msg00440.html and especially the post I link to here: http://forums.wolfram.com/mathgroup/archive/2009/Feb/msg00424.html Simply put, what is the value of? Cos[Dynamic[Pi]] Answer...Cos[Dynamic[Pi]], but because of the way Dynamic typesets, it will look like Cos[Pi] (because Dynamic[Pi] looks like Pi). That is because Dynamic[Pi], in the Shift+Enter evaluation, always evaluates to Dynamic[Pi]. Dynamic is a HoldFirst function which never evaluates its argument...it merely creates a front end construct which evaluates and displays its argument. > I understand the point you make about if a colon were placed and no > output were generated but what is your definition of "first displayed"? It actually shows up in the front end. > I > guess this must be another point of difference because I would consider > the first display of the dynamic module as being the first time I see the > list {plot, "slider", g[0]} rendered. Yes, that's correct. But why would you expect 'plot' or 'g' to magically update, since they are not inside of Dynamic? > So when I first see {plot, "slider", g[0]} the initialized value of plot > and g are not rendered. Apologies if it seems I'm laboring this point but > it remains confusing. > So it seems that the key to understanding this now becomes what the > definition of "display" is. Am I correct is saying that if a > DynamicModule is displayed -- and I await what this means -- the > initialization will have taken place and therefore the initialized value > will be shown in the display? The initialization will have taken place, but initialized values will only show if the FE is kicking off further evaluations to actually display them...which is what Dynamic does. > FWIW I had assumed a display to be the rendered output. That is correct. > thanks > > > Mike Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc.