So, if you have a package formatted like so:
BeginPackage["MyPackage`"];
Begin["`Private`"];
someFunction:=(
x=3;
y=4;
out=x + y;
)
End[];
Begin["`Private`"];
anotherFunction:=(
x=5;
z=7;
out= x + z;
)
End[];
EndPackage[];
Is x treated locally? Like if you call the function anotherFunction, does Mathematica know the difference between the xs since they both have the context MyPackage`Private or is each instance of Private independent of the other? If so, then why use Module to make variables local rather than the Private context.
someFunction"] and Begin["anotherFunction"] instead of Begin["Private"] to truly localize the variables inside the functions? – Joe Blow Jun 16 '17 at 06:22Privateis only a name, there is nothing special about it. So there is no difference if you use it or your names. Sure it will shieldx-esfrom one and another in those functions in this case, but only if there isn'txalready on $ContextPath, e.g. inMyPackage`. Then new symbols won't be created. ... – Kuba Jun 16 '17 at 06:27Moduleis the way to go as it shields what it sees, no matter which context is specific symbol in. – Kuba Jun 16 '17 at 06:29