I've been trying to use Manipulate to do interactive plotting, but I've been running into a few problems with saved expressions. I have an expression saved as "func" and I want to work with it and then plot it later. But I can't seem to get it to work. For example, this works fine

I assume that this has something to do with when expressions are evaluated and the difference between expressions and functions, but I'm new to Mathematica and and I'm not sure on on the difference between the two.

What in the last code bit is it that you thing doesn't work? It seems to work perfectly. Have you tried clearing your kernel and making sure you don't have other things interfering?
–
jVincentFeb 21 '13 at 9:31

Thanks for the catch. I revised the question.
–
jmbejaraFeb 21 '13 at 9:46

When you apply a rule such as f[x_]->rhs, or use a definition such as
f[x_]:=rhs, Mathematica implicitly has to substitute for x everywhere
in the expression rhs. It effectively does this using the /. operator.
As a result, such substitution does not respect scoping constructs.
However, when the insides of a scoping construct are modified by the
substitution, the other variables in the scoping construct are renamed.

I'm not seeing how this is helpful in this application. Can you give an example?
–
Mr.Wizard♦Feb 27 '13 at 17:30

@Mr.Wizard Really? Well, thank you for pointing this out. This serves to inject an expression inside Manipulate[Plot[...]] just like with or a Function argument and is as such a direct answer. The example is the last line.
–
AjasjaFeb 27 '13 at 21:17

@Mr.Wizard It's also a useful reminder that Manipulate can be returned just like any other expression. (which I tended to forget when I was learning MMA). Using a pattern declaration one can also better control evaluation as I learned here: mathematica.stackexchange.com/questions/5951/…)
–
AjasjaFeb 27 '13 at 21:27

I suspect that I am confused by your wording. I read "automatic scoping of named patterns with SetDelayed" to refer to the automatic renaming of parameters (pattern names) in nested scoping constructs, e.g. With[{body = x^2}, Function[x, body]]. I am neither seeing that behavior here nor understanding how it would help; to the contrary it would seem that this renaming, if it happened, would prevent proper function of the Manipulate. If this is not what you refer to what do you mean by "automatic scoping"?
–
Mr.Wizard♦Feb 28 '13 at 4:41

@Mr.Wizard I was refering to When you apply a rule such as f[x_]->rhs, or use a definition such as f[x_]:=rhs, Mathematica implicitly has to substitute for x everywhere in the expression rhs. It effectively does this using the /. operator. As a result, such substitution does not respect scoping constructs. However, when the insides of a scoping construct are modified by the substitution, the other variables in the scoping construct are renamed from here reference.wolfram.com/mathematica/tutorial/….
–
AjasjaFeb 28 '13 at 9:18

+1 for another method. When you say "formal" I think of formal symbols e.g. \[FormalA], which might be a superior method as they cannot have values accidentally assigned.
–
Mr.Wizard♦Feb 21 '13 at 11:31

So, to be sure I understand, \[FormalA] can never be assigned a value and so it works. \[Alpha] and the like, however, are not write protected in the same way that a and b are not protected, but still works. What is different, then, about \[Alpha] and \[Beta] that makes this work? Are they something in between regular a and \[FormalA]?
–
jmbejaraFeb 21 '13 at 11:51

@jmbejara No, \[Alpha] and \[Beta] are just like an other symbols. What makes this work has nothing to do with "formal symbols" but instead it is because a and b appear explicitly in the body of Manipulate.
–
Mr.Wizard♦Feb 21 '13 at 13:49

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.