So, I'm trying to create two sets of similar variables, for example: a
, b
, c
. This would be used with the same function. What I tried to do is creating two contexts "A`"
and "B`"
where the variables would have their own association:
Begin["A`"];
a=1;
b=2;
c=3;
End[];
Begin["B`"];
a=4;
b=5;
c=6;
End[];
Then I desired to create a function in the Global`
context so it would be accessible to the former ones:
f=Compile[{x},(a*x + b)/c]
Then, I would go back to the desired context "A`"
or "B`"
, and since no function f
is defined there Mathematica would look for the next f
in $ContextPath
order. But, of course, since the function is defined in the Global`
context, the values of a, b, and c used in its definition need to be in the same Context
(at least the way I defined it).
The thing is, what I'm trying is to be able to reuse functions so I don't have to write two similar programs for two different sets of variables.
I was hoping, when I found out about Context
, to be able to move from one context to the other and by that selecting the right set of variables to be used by the functions. Is it possible? If not, what would be the best approach?
Also I found a little confusing how Contexts are explained in the Help Section. I thought that they should be thought of like directories. So if I'm in Global`
and evaluated Begin["`A`"]
, when I then evaluated $ContextPath
I should get {...,System`, Global`, A`}
, which I didn't.
Thanks