10
$\begingroup$

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[
   $CellContext`MyDateString[], 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$$18$101847`,System`}; definitions in context Notebook$$18$101847` may shadow or be shadowed by other definitions.
  • (caveat scrutor: System`DateString 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?

$\endgroup$

1 Answer 1

6
$\begingroup$

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.

Further reading

  • You can find more information in

    AdvancedDynamicFunctionality / Automatic Updates of Dynamic Objects

    tutorial/AdvancedDynamicFunctionality#440620996 (help browser link)

  • You can also monitor, to some extent, information flow, between the Kernel and the FrontEnd, with LinkSnooper:

    How to set up LinkSnooper for monitoring FrontEnd--Kernel communication?

  • Yes $CellContext has nothing to do with it.

    By creating $CellContext`DateString[] it is parsed to Global`DateString[], which does not exist and is conflicting with System`DateString, see more in:

    How does $CellContext` work?

$\endgroup$
6
  • $\begingroup$ 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? $\endgroup$ Commented Jul 10, 2018 at 7:47
  • $\begingroup$ @kkm If I understood you correctly, yes, that is what I mean. $\endgroup$
    – Kuba
    Commented Jul 10, 2018 at 7:53
  • 3
    $\begingroup$ BTW, MMA 11.3 came with a preset link snooper, you no longer need to set it up, just select from the list available kernels. $\endgroup$ Commented Jul 10, 2018 at 7:53
  • $\begingroup$ @kkm wow, wasn't aware of that, thanks. $\endgroup$
    – Kuba
    Commented Jul 10, 2018 at 7:54
  • 2
    $\begingroup$ “wasn't aware of that, thanks” – my pleasure! This community is awesome! :) $\endgroup$ Commented Jul 10, 2018 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.