1
$\begingroup$

I am building a fairly large application in Mathematica, and globally scoped variables are causing issues.

I would like globally scoped variables to be out-of-scope for my expressions, except by request.

Here is a simple, albeit contrived, example (where //GlobalScope is something with the intended behavior, I guess):

B := 0;

f[x_, m_, b_] := m*x + b;

Manipulate[
 Plot[
  f[X, M, B], 
  {X, 0, 10}
 ], 
 {M, 0, 10}, 
 {B, 0, 10}
]//GlobalsAvailable

should be allowed, but

B := 0;

f[x_, m_, b_] := m*x + B;

Manipulate[
 Plot[
  f[X, M, B], 
  {X, 0, 10}
 ], 
 {M, 0, 10}, 
 {B, 0, 10}
]//GlobalsAvailable

should not be allowed.

I'm also open to suggestions which fix the underlying problem (which is caused by the combination of mutability, global scope and the reactive development style encouraged by notebooks).

$\endgroup$
2
  • $\begingroup$ If you use LocalizeVariables -> False, then variables associated with the controls will have global scope. x = 10; {Manipulate[x, {x, 0, 40}, LocalizeVariables -> False], Dynamic[x]} By default Manipulate uses LocalizeVariables -> True Is this what you needed? $\endgroup$ – Nasser Jul 10 '14 at 17:30
  • $\begingroup$ Possible duplicate? mathematica.stackexchange.com/q/31687/12 (unless I misunderstood) $\endgroup$ – Szabolcs Jul 10 '14 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.