# Better alternative to Hold/ReleaseHold for postfix application of Monitor

Trying to Monitor a process using the postfix notation, as in

Table[Pause[n/10], {n, 5}] // Monitor[#, n] &


fails: the argument Table[Pause[n/10], {n, 5}] is evaluated before being passed to the pure function Monitor[#,n]& because that function does not have the attribute HoldAll like Monitor itself.

An option is to Hold explicitly and release the hold inside the pure function:

Table[Pause[n/10], {n, 5}] // Hold // Monitor[ReleaseHold[#], n] &


Is there a simpler/cleaner/shorter way? Obviously Monitor[Table[...],n] works, but I'd rather separate the code from the monitoring.

• I tend to use an infix version Table[...] ~Monitor~ n. – wxffles Apr 18 '16 at 21:47
• Ah, I was wrong to insist on postfix. The infix notation is great, I'll use that. – Bruno Le Floch Apr 19 '16 at 20:37

You can use Unevaluated

Unevaluated@Table[Pause[n/10], {n, 5}] // Monitor[#, n] &


The neater way will be to use the infix version as suggested by wxffles in the comments, but your question specifically asked for postfix so... For completeness, here it is

Table[Pause[n/10], {n, 5}] ~Monitor~ n


Wrap your Monitor call in a Function object endowed with a holding attribute:

Table[Pause[n/10], {n, 10}] // Function[{input}, Monitor[input, n], HoldAll]


This will work as though you had wrapped Monitor around your Table.