# Why does Part[list, n] work in one place, but not work consequently?

GROUPS:
 As a new Mathematica user I am puzzled by the following, where the Part[list, n] function - or more accurately list[] - doesn't seem to have consequent results. For example, in MM 9 on Windows 7 if I say:f[x_, y_] := (x + y)^2curves = Expand[Thread[f[{1, 2, 3}, {x, y, z}]]]bounds = {{x, -10, 10}, {y, -10, 10}, {z, -10, 10}}Plot[curves[[1]], {x, -10, 10}]this works, but Plot[curves[[1]], bounds[[1]]] returns an error even though bounds[[1]] returns {x,-10,10}. Anbody know why this is?
4 years ago
17 Replies
 That is because Plot is HoldAll, however one can do Plot[curves[[1]], Evaluate[bounds[[1]]]]
4 years ago
 OK - I get it, that solves it. Thanks very much!
4 years ago
 This is an order of operations issue - you need to make sure that the second argument to Plot (bounds[[1]]) is evaluated at the appropriate time. One way of doing this is to use the Evaluate function:http://reference.wolfram.com/mathematica/ref/Evaluate.htmlFor example, this should work:Plot[curves[[1]], Evaluate@bounds[[1]]]Note that the reason for this special behavior is that the Plot function has the attribute HoldAll:Attributes[Plot]which means that the arguments to Plot are maintained in an unevaluated form.EDIT: Oh well, Ilian already answered this.
4 years ago
 OK - why does HoldAll only affect the second argument to Plot[ ] and not the first?
4 years ago
 HoldAll does affect all arguments. The evaluator passes the first argument to Plot unevaluated, which is then free to use it in any way, including evaluation at each sample point.
4 years ago
 That makes sense, but in what way is the simple list {x, -10, 10} passed to Plot[ ] when the list is provided as a literal instead of the result of a function call? If both are unevaluated, wha'ts the difference between the literal and the result of bounds[[1]]? Sorry about all the questions, but I'd lke to get a proper handle on how MM does things..
4 years ago
 Plot needs a valid plot range specification, which {x, -10, 10} is, but bounds[[1]] --- in its unevaluated form --- is not.
4 years ago
 Sorry Ilian, I think I'm expressing myself badly. Why does Plot[ ] evaluate the result of curves[[1]] and not of bounds[[1]]?
4 years ago
 I looked up HoldAll in the documentation, where it's defined as: an attribute which specifies that all arguments to a function are to be maintained in an unevaluated form. Simple enough, but that doesn't explain why Plot[ ] then evaluates curves[[1]] but not bounds[[1]].
4 years ago
4 years ago
 It might be more clear to you what is happening if you wrapped FullForm around the results:FullForm[curves[[1]]]FullForm[bounds[[1]]]bounds[[1]] has curly braces around it, indicating it is a list.  curves[[1]] is just 3 terms added together, so it will have the head Plus (indicating addition).
4 years ago
 Thanks Karl - my problem is not with the head of the arguments, it's with the logic being followed. If HoldAll applies to ALL arguments, why is curves[[1]] evaluated by Plot[ ] and not bounds[[1]]? That's what seems illogical to me. I though that Plus might be something that needed less(?) evaluation than List and that's what's causing the problem? Does the list have to be flattend first before being evaluated and this is what's causing the 'problem'?
4 years ago
 Perhaps I should have emphasized this -- HoldAll only controls what happens with the arguments before Plot is called. What may take place inside of Plot is a different story, but does not contradict the HoldAll documentation in any way.There can be, of course, further questions about the design and implementation, for example why does Plot need to be HoldAll. Other people are better qualified to answer that, but I believe it makes some of the advanced visualization machinery much easier to implement.
4 years ago
 In other words: it is like it is. LOL! Thanks for the time and trouble guys.