Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6537
| From | Armand Tamzarian <mike.honeychurch@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | What is the point of having Initializations in DynamicModule and Manipulate? |
| Date | 2011-11-19 11:53 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <ja85bl$ik0$1@smc.vnet.net> (permalink) |
I'd be interested in feedback from other users about the way in which
Initializations works within DynamicModule (and Manipulate?). It is
fair to say that I expected an initialization to occur "initially."
That is to say I expected Initialization content to be evaluated prior
to the body of the DynamicModule. I have exchanged emails with tech
support about this. Attached is an example sent to me by tech support.
ClearAll[plot, g];
(* and in a separate cell *)
DynamicModule[{c}, {plot, Slider[Dynamic[c]], g[Dynamic@c]},
Initialization :> (g[x_] := Cos[x]; plot = Plot[g[x], {x, 1, 10}]),
UntrackedVariables -> {g}]
It is important for this example to keep the ClearAll line in a
separate cell so that the global variables are only cleared once. On
my system (OS X 10.6.8, Mma 8.0.4) the output is a list
{plot, "slider", g[0.]}
where "slider" is the actual rendered slider but plot is the word
(unset variable) plot. In other words Global`plot has no value at the
time the body of the DynamicModule is evaluated. Ditto Global`g.
If you evaluated the cell (the second cell with the DynamicModule) a
second time a plot graphic appears in the list and g[0.] becomes
Cos[0.]. This is not surprising because Global`plot and Global`g now
have a value.
Wolfram have indicated that this is working as designed -- which is
presumably why this example was sent to me of how this should work. If
that is the case it seems poorly designed because (and it is here I
would like feedback) users would expect initializations to be
evaluated prior to the body of the DynamicModule -- otherwise what is
the point?
I'd appreciate the thoughts of other users about this.
Additionally I have been told by Wolfram that wrapping Dynamic around
the variable(s) that are not being evaluated will trigger the
evaluation. But why would a user want to make plot or g Dynamic? It
seems to me that the entire purpose of having an Initialization is to
evaluate this "one off" variable/functions.
thanks
Mike
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
What is the point of having Initializations in DynamicModule and Manipulate? Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-11-19 11:53 +0000
csiph-web