Creating reliable real-time monitors for variables

We can create a real-time monitor for such a variable:

CreatePalette@Panel @Row[{"x = ", Dynamic[x]}] 

(This is more interesting and useful if x turns out to be something like $Assumptions . It's so easy to set a value and then forget about it.)

Unfortunately, this stops working if the kernel is restarted ( Quit[] and then evaluate something). The palette will no longer display at x .

Is there a way to do this so that it continues to work even during kernel sessions? I find that I restart the kernel quite often. (If the resulting palette causes the kernel to start automatically after Quit , which is fine.)


Update: As mentioned in the comments, it turns out that the palette stops working only if we leave by evaluating Quit[] . When using Evaluation -> Quit Kernel -> Local it will continue to work.


+7
source share
2 answers

I can only guess, because on my Ubuntu the situation here seems to be buggy. The trick to exit the menu, as Leonid suggested, did not work here. One more thing: in a new Mathematica session with only one laptop open:

 Dynamic[x] x = 1 Dynamic[x] x = 2 

gives the expected

 2 1 2 2 

Entering the next line of Quit , evaluating and entering, then x=3 updates only the first of the dynamic [x].

However, did you check the team

 Internal`GetTrackedSymbols[] 

This gives not only trackable characters, but also an additional identifier that contains dynamic content. If you find out what exactly these numbers are explored in other functions that you will find in the internal context, you can add your Dynamic-content palette manually after restarting the kernel.

I thought I had something similar with

 Internal`SetValueTrackExtra 

but at present I cannot reproduce the behavior.

+3
source

@halirutan reply jarred my memory ...

Have you ever encountered: Experimental/ref/ValueFunction ? (documentation address)

Although there are no examples in the documentation, the "More Information" section provides the following tidbit:

The assignment ValueFunction[symb] = f indicates that whenever symb gets a new value val , the expression f[symb,val] should be evaluated.

+3
source

All Articles