1

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).

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • 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? – Nasser Jul 10 '14 at 17:30
  • Possible duplicate? http://mathematica.stackexchange.com/q/31687/12 (unless I misunderstood) – Szabolcs Jul 10 '14 at 18:28

0 Answers0