Practically speaking, this is what I actually do:
First, if I need a variable to be dynamically updated, I use a global foo
. Global side effects are generally a questionable programming practice, but we're basically just monitoring a command, not programming. In my practice, foo
functions as a reserved symbol that is unsafe to use in a program but fine to assign a value at anytime. Substitute your own reserved symbol as you wish. I have a list of them that I would never use in a program.
Second, I use PrintTemporary@Dynamic@{Clock[Infinity], foo & other data}
to get just one temporary, dynamically-updated cell. You might want to use Short[foo]
so that you don't accidentally try to display a gigabyte array. Monitor
does something like this, but I want something more flexible often enough that I just always start with PrintTemporary@Dynamic@{Clock[Infinity],...}
and think about what I want shown. And having the running clock is also often convenient (for instance, if it stops running, or minutes after something that should take only seconds.)
Examples:
foo=0;
PrintTemporary@Dynamic@{Clock[Infinity], foo}
(foo++;f[##])& @@@ list
foo=0;
PrintTemporary@Dynamic@{Clock[Infinity], i, Short[foo]}
Table[f @@ (foo = list[[i]]), {i, Length@list}]
foo = "init";
PrintTemporary@Dynamic@{Clock[Infinity], foo};
f[foo = ##] & @@@ RandomInteger[9, {20000000, 4}];
Bonus (watch the timefront evolve instability):
PrintTemporary@Dynamic@{Clock@Infinity, foo};
NDSolve[{D[u[t, x], t, t] == 2 D[u[t, x], x, x]^3,
u[0, x] == Sin[Pi x], Derivative[1, 0][u][0, x] == Sin[Pi x],
u[t, 0] == 0, u[t, 5] == 0},
u, {t, 0, 10}, {x, 0, 5}, Method -> "MethodOfLines",
StepMonitor :> (foo = ListLinePlot[Head@u[t, x], PlotLabel -> t])]