If I define a function that returns a Manipulate object, and the Manipulate has a local variable inside of it, the local variable is highlighted in red. Here's an example of what I mean:

MyTrigDemo[f_] := Module[{plot},
plot[A_] := 
Plot[A Sin[2 \[Pi] f x], {x, 0, 1}, PlotRange -> {-3, 3}];
Manipulate[plot[A], {A, 0, 2}]

displays as (v10.0.0.0)

enter image description here

Despite the scary highlighting, the function seems to work as I expect. Is this structure inadvisable for some reason?


1 Answer 1


Quoting from here:

Module variables should never appear inside Dynamics or Manipulates internal to that Module.


In fact, this rule is so straightforward and universal, there's no reason that we shouldn't have some advisory syntax highlighting which points out the badness...I intend to do this for a future release.

See also here in the documentation for why doing this is a bad idea: Module vs DynamicModule.

In short, Module variables are meant to cease existing as soon as that Module exits, but Manipulate would try to continue using them.


Not the answer you're looking for? Browse other questions tagged or ask your own question.