A minimal example for the Bonus in Can a Dynamic be attached to the single elements of a list?
DynamicModule[{foo = Hold[$1, $2], $1 = 0, $2 = 0},
{
Dynamic[Print["redrawing first"]; foo[[1]]],
Dynamic[Print["redrawing second"]; foo[[2]]],
Button["first", ++$1],
Button["second", ++$2]
}
]
Observe the Messages window as these buttons are pressed. The redraw messages are printed independently after the initial evaluation, i.e. you can get a message list like:
redrawing first
redrawing second
redrawing first
redrawing first
redrawing first
redrawing first
redrawing second
(corresponding to 4, 1, in the expression)
By what mechanism does Mathematica track the value of $1
or $2
changing and update each Dynamic individually despite neither Symbol appearing explicitly in the bodies?
$1
and therefore$1
is tagged with the dynamic object number for foo[[1]]. That is confirmed by the result of Internal`GetTrackedIDs[]. Therefore, each time when we press the button for $1, also the output of foo[[1]] is updated. $\endgroup$