# What makes a function ticklish?

The Advanced Dynamic Functionality tutorial informally describes a ticklish function as follows:

Every time you evaluate RandomReal[], you get a different answer, and you might think that Dynamic[RandomReal[]] should therefore constantly update itself as fast as possible. But this would normally not be useful, and would in fact have negative consequences for a number of algorithms that use randomness internally[...]

For this reason, RandomReal[] is not "ticklish", in the sense that it does not trigger updates[...]

The function Clock is intended specifically as a time‐based function that is ticklish.

How to tell if a function is ticklish? What makes it such?

Naturally, it's easy to see that Clock[] is ticklish, as is another function that evaluates Clock[], even if it discards the intermediate result. Thus ticklishness in not a property of the function's symbol (this rules out an attribute, option, or a list of predefined ticklish function heads):

MyClock[]:=Clock[];
MyDateString[]:=(Clock[]; DateString[]);


then

Dynamic[Clock[]]
Dynamic[MyClock[]]
Dynamic[MyDateString[]]
Dynamic[DateString[]]


The first three output cells update dynamically, while the fourth does not. How do they know they need to update? At the first sight, there are differences in the box form of the last two output cells:

Cell[BoxData[
DynamicBox[ToBoxes[
$CellContextMyDateString[], StandardForm], ImageSizeCache->{141., {1., 10.}}]], "Output", CellLabel->"Out[131]="] Cell[BoxData[ DynamicBox[ToBoxes[ DateString[], StandardForm], ImageSizeCache->{141., {1., 10.}}]], "Output", CellLabel->"Out[132]="]  but that aha! was a total flop, as removing the $CellContext from the first cell of the two did not make it non-ticklish, while adding it to the second simply broke its display red with a peculiar error message

DateString::shdw: Symbol DateString appears in multiple contexts {Notebook$$18101847,System}; definitions in context Notebook$$18$101847 may shadow or be shadowed by other definitions.  • (caveat scrutor: SystemDateString seemed to have disappeared after that, so I had to restart the kernel to proceed at this point, even though I Remove[]d the definition in the Notebook$$18$101847​ context; you may not want to repeat the experiment and simply take my word for it at this point.)

And in fact, simply writing the explicit box form into the notebook

NotebookWrite[EvaluationNotebook[],
Cell[BoxData[ToBoxes[Dynamic[MyDateString[]]]], "Output"]]


generates a self-updating cell.

So what does make a function ticklish?

I should emphasize that, due to limited documentation, this is only an educated guess. Additionally, any computer science term (e.g. tree) I use is not strict as I have no CS/IT background.

### Shortly

So what does make a function ticklish?

Its dependency tree. If it contains a ticklish function it will be ticklish. (Roughly)

Which functions are ticklish by design? I am not aware of any documentation about that.

### ?

When should Dynamic be updated? It depends on its argument and options (TrackedSymbols, UpdateInterval).

The argument's dependencies (with respect to TrackedSymbols) are used to build a tree of symbols that should trigger that Dynamic object updates, together with scheduled updates governed by 'ticklish' functions and UpdateInterval.

Then, when any of those symbols changes, or when 'the time comes' for scheduled updates, the Kernel tells the FrontEnd to udpdate a specific DynamicObject.

• Yes $CellContext has nothing to do with it. By creating $CellContextDateString[] it is parsed to GlobalDateString[], which does not exist and is conflicting with SystemDateString, see more in:
How does $CellContext work? • Interesting, thanks. I thought about the snooper, but it's a deluge. I'll set up a slower Clock[] and play with it perhaps. Thanks for reminding me that $CellContext is purely a symbolic placeholder, I forgot about it. So your take is that there is a list of known ticklish functions, and an expression is ticklish if it's body references another ticklish symbol, and the grounding of this recursion is still in a manifest list of internal ticklish functions. Am I understanding you correctly? – kkm Jul 10 '18 at 7:47