Could someone please explain the following behaviors?
I don't know if it's related to TrackedSymbols
, assignment, evaluation of rhs of assignment, or initialization in DynamicModule
.
DynamicModule[{x, y},
Column[{
Slider[Dynamic[x]],
Dynamic[Refresh[y = x, TrackedSymbols -> {y}]],
Dynamic[y]
}]]
Without the initilization of x
and y
, only the 2nd Dynamic
updates.
And, if y=x
is changed to y=x+1
, neither Dynamic
updates;
y=x++
, or RandomReal[]
, which of course makes Slider
pointless, both Dynamic
update.
Now if I change the initilization part to e.g. x=0,y=0
,
then in the case of y=x, y=x+1, y=x++
, neither Dynamic
updates;
only those with y=RandomReal[]
updates.
I don't know if the above is useful in real life. I just create them to understand better the behavior Refresh
wrapped in Dynamic
and if it's OK/meaningful to use assignment in Refresh
.
Thanks a lot.
=================================
I put my newest questions here for better readability.
I'd like ask regarding #4 of the generic situation.
Q1: Is my understanding correct? when Dynamic@Refresh
runs for the 1st time, y's state is changed from no_initial value to y=0, which is passed by x via assignment.
Q1-1: And when y is provided an initial value of 0, in the case of y=x++, y's state doesn't change, when Dynamic@Refresh
runs for the 1st time, and therefore, it doesn't run into Infinity
, unless use ++x
, as you suggested.
Q2: When I drag the slider thumb, why the newest value of x can't be passed to y via assignment? Is it because I set explicit trackedsymbol to {y}. This part is still quite confusing for me. (The situation with x++ or RandomReal[] isn't the same as y=x+1, since neither of them is related to slider).