Re: Monitor bug or feature
- To: mathgroup at smc.vnet.net
- Subject: [mg84127] Re: Monitor bug or feature
- From: Albert Retey <awnl at arcor.net>
- Date: Mon, 10 Dec 2007 22:19:42 -0500 (EST)
- References: <fjj1nk$g5b$1@smc.vnet.net>
Mark Fisher wrote:
> Hi all,
>
> Monitor[Table[Pause[.1]; i, {i, 10}], i]
>
> works as I expected, but
>
> Table[Pause[.1]; i, {i, 10}] // Monitor[#, i] &
>
> does not: It does not produce any "monitoring".
>
> Are there other examples where
>
> f[x, a]
>
> and
>
> f[#,a]&[x]
>
> produce different "effects". (Clearly the Heads of the expressions are
> different.)
>
> I'm guessing my surprise regarding this feature of Monitor reflects
> the fact that I really haven't made any attempt to understand Dynamic
> etc.
I don't think this has anything to do with Dynamic but with evaluation
order. Note that Monitor needs to have the attribute HoldAll to be able
to do what it does. Also note that a function like f[#,a]& does not have
any attributes, so the arguments are evaluated before fed to the
function body. For the first example that means Table is evaluated
before the resulting list is passed to Monitor, so Monitor sees {1, 2,
3, 4, 5, 6, 7, 8, 9, 10}, nothing that it can do much with and so just
returns. Note that this works as expected:
Table[Pause[.1]; i, {i, 10}] //
Function[Null, Monitor[#, i], HoldAll]
So the answer to your second question seem to be yes, whenever a
function f has any Hold attributes attr, something like f[#]&[x] might
be different from f[x], but I think Function[Null,f[#],attr][x] should
give the same in almost all cases, although I think it would be possible
to construct counterexamples...
hth,
albert