Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
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 at 17:30
    
Possible duplicate? mathematica.stackexchange.com/q/31687/12 (unless I misunderstood) –  Szabolcs Jul 10 at 18:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.