Print function is the most basic and strong but foolish tool for programming till the last. Dynamic can be a advanced tool for the monitoring, however, OOP styled monitor can improve this condition. My project is to develop a running Wolfram language monitor tool that shows the symbol, list, etc. including oscilloscope like viewer.
Developed tool is composed of class-definition, constructer, and the probe-instance that should be inserted into a target program.
Following is class-definition, (modified 2017/5/18, replaced controversial AppendTo[] to RotateLeft[], because AppendTo[] is wondering if this function call might be the cause of system clash. )
PROBE - CLASS;
scope[nam_] :=
Module[{dx, xrange = 50, data = ConstantArray[0, 50], ps = 0},
PROBE - METHOD;
probe[nam[x_]] ^:= (
If[ps == Infinity, Return[]];
data = RotateLeft[data];
data[[-1]] = x;
dx = x;
Pause[ps]);
SHOW - METHOD;
showBox[nam] ^:=
CreateDocument[{Column[{Pane[
Row[{nam, " -> ", Dynamic[dx]},
BaseStyle -> {FontSize -> 16, FontFamily -> "Times"}],
ImageSize -> {350, 320}],
Pane[
Row[{"Pausing-time ",
SetterBar[Dynamic[ps], {Infinity, 0, 0.2, 1}]}],
ImageMargins -> 10]
}
]},
WindowTitle -> nam, WindowElements -> {"MagnificationPopUp"},
WindowSize -> {400, 315}];
SHOW - PLOT - METHOD;
showPlotBox[nam] ^:=
CreateDocument[{Column[{Pane[
Row[{nam, " -> ", Dynamic[dx]},
BaseStyle -> {FontSize -> 16, FontFamily -> "Times"}],
ImageSize -> {400, 30}],
Pane[
Dynamic[ListLinePlot[data,
PlotRange -> {{0, xrange}, Automatic}]]],
Pane[
Row[{"Pausing-time ",
SetterBar[Dynamic[ps], {Infinity, 0, 0.2, 1}]}],
ImageMargins -> 10]
}
]},
WindowTitle -> nam, WindowElements -> {"MagnificationPopUp"},
WindowSize -> {400, 315}];
];
OOP instance constructer, where any number of probe-instances can be made,
objectList = {$x, $y};
Map[scope, objectList];
showPlotBox[$x]; showBox[$x]; showPlotBox[$y];
A sample target program probe inserted is,
Do[probe[$x[Random[]]]; probe[$y[Random[]]]; Pause[0.5], {100}];
Because the probing instances are encapsulated by OOP, you can find that the probe is always "Global" by asking "? probe", then you can remove monitoring windows at any time.