6

According to the documentation AppendTo[s,elem] is equivalent to s = Append[s,elem]. But then

y = {}; Plot[y = Append[y, x]; Sin[x], {x, Pi/4, Pi/2}]

works as intended, while

y = {}; Plot[AppendTo[y, x]; Sin[x], {x, Pi/4, Pi/2}]

produces the error message

AppendTo::rvalue: {[Pi]/4} is not a variable with a value, so its value cannot be changed.

Can someone explain what is going on?

freddy90
  • 851
  • 4
  • 12

1 Answers1

8

It is an evaluation issues. I can't pin the exact sequence now, but here is a workaround

y = {}; 
Plot[AppendTo[y, x]; Sin[x], {x, Pi/4, Pi/2}, Evaluated -> False]
y

Mathematica graphics

Which now gives the same exact output as

y = {}; 
Plot[y = Append[y, x]; Sin[x], {x, Pi/4, Pi/2}]

You can see this answer using-evaluate-and-evaluated-true-in-plot for more information about what Evaluated do.

Nasser
  • 143,286
  • 11
  • 154
  • 359