Shortly, definitions in form of e.g. x:= RandomReal[]
have to be avoided inside DynamicModule[{x}, ...]
. Why?, this Prints
immediately:
DynamicModule[{x}, x := Print[1]; {}]
It hit us hard in the past, e.g.:
- Button evaluation inside DynamicModule
- comments under ShearingTransform and Dynamic
- comments under How to combine manipulate and eventhandler
So what is the official rule here?
ref / DynamicModule / Details and Options / (-4)th bullet point
Ordinary values of symbols are saved in the first argument of the
DynamicModule
; other values are saved in the setting for theDynamicModuleValues
option.
This is almost useless since "Ordinary values of symbols" and "other values" have no real meaning in Mathematica.
J. Fultz in ShearingTransform and Dynamic:
An issue which is causing confusion among the commenters is that
DynamicModule
, sadly, does not supportSetDelayed
on its member variables.SetDelayed
is silently translated toSet
.
Closer but not quite there yet, x[]:=RandomReal[]
will work well.