For teaching purposes, I want to create a Mathematica notebook that will "notice" when the user defines or redefines a variable or function of a particular name, so that it can check the value and take some appropriate action. For example, the notebook might be monitoring the symbol "foo", so that if the user executes foo = 22/7
at any time, code that I've written and hidden (perhaps in an invisible cell, perhaps via an initialization cell that loads a package I've written) might write out some hint text, e.g. "You've guessed the right variable name, but not the right value yet." I know I could do this by having the user click an explicit "test" button or some such thing, but I'd rather have my code monitor the user invisibly and take action without the user invoking it.
Is this possible? If so, how might it be implemented?
$NewSymbol
, etc. $\endgroup$Dynamic[...]
that will detect subsequent changes… $\endgroup$