Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating robust real-time monitors for variables

We can create a real-time monitor for a variable like this:

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

(This is more interesting and useful if x happens 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 re-launched (Quit[], then evaluate something). The palette won't show changes in the value of x any more.

Is there a way to do this so it keeps working even across kernel sessions? I find myself restarting the kernel quite often. (If the resulting palette causes the kernel to be automatically started after Quit that's fine.)


Update: As mentioned in the comments, it turns out that the palette ceases working only if we quit by evaluating Quit[]. When using Evaluation -> Quit Kernel -> Local, it will keep working.


  • Link to same question on MathGroup.
like image 889
Szabolcs Avatar asked Jan 06 '12 10:01

Szabolcs


2 Answers

I can only guess, because on my Ubuntu here the situations seems buggy. The trick with the Quit from the menu like Leonid suggested did not work here. Another one is: on a fresh Mathematica session with only one notebook open:

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

gives as expected

2
1
2
2

Typing in the next line Quit, evaluating and typing then x=3 updates only the first of the Dynamic[x].

Nevertheless, have you checked the command

Internal`GetTrackedSymbols[]

This gives not only the tracked symbols but additionally some kind of ID where the dynamic content belongs. If you can find out, what exactly these numbers are and investigate in the other functions you find in the Internal context, you may be able to add your palette Dynamic-content manually after restarting the kernel.

I thought I had something like that with

Internal`SetValueTrackExtra 

but I'm currently not able to reproduce the behavior.

like image 70
halirutan Avatar answered Sep 19 '22 22:09

halirutan


@halirutan's answer jarred my memory...

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

Although the documentation contains no examples, the 'more information' section provides the following tidbit:

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

like image 40
telefunkenvf14 Avatar answered Sep 19 '22 22:09

telefunkenvf14