MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: different results for Standard vs Prefix forms

On 7/30/10 at 6:55 AM, yaroslavvb at (Yaroslav Bulatov) wrote:

>First one works, but second one doesn't, why?
>Block[{n = 2}, Plot[n x, {x, 1, 2}]]
>Block[{n = 2}, #] &@Plot[n x, {x, 1, 2}]

In the first instance, Block makes n a local variable and
assigns a numeric value to it. This makes the argument to 2 x
which works fine.

In the second instance, the Plot command is evaluated first. In
this case, n has no assigned value so Plot cannot determine how
to plot the curve and plots nothing. The variable n does not get
its assigned value until after Plot has been executed.

You can get something like the second instance to work by
preventing Plot from being evaluated first as follows:

Block[{n = 2}, #] &@Unevaluated@Plot[n x, {x, 1, 2}]

But this seems like a rather convoluted way to do things.

  • Prev by Date: Re: Packages designed for use in player pro
  • Next by Date: ODE solution transfer
  • Previous by thread: Re: different results for Standard vs Prefix forms
  • Next by thread: A problem with Thread[]