I have problems with name space shadowing which I do not know how to resolve. I have two packages which depend on each other. Here is example of two files
fooPackage.m:
BeginPackage["fooPackage`",{"barPackage`"}];
top::usage = "This is top level funciton";
foo::usage = "Text";
Begin["Private`"];
top[arg___]:=bar[];
foo[arg___]:=Print["This is foo!"];
End[];
EndPackage[];
barPackage.m:
BeginPackage["barPackage`", {"fooPackage`"}];
bar::usage = "";
Begin["Private`"]
bar[arg___] := (Print["This is bar!"]; foo[arg])
End[];
EndPackage[];
Now if I use it as I intended:
Quit[];
Needs["fooPackage`", "/home/johu/temp/fooPackage.m"]
top[]
$ContextPath[[;; 2]]
This is bar! Private`foo[] {"fooPackage`", "barPackage`"}
I would get bar working if I loaded another package as top level which however does not contain the definition top
Quit[];
Needs["barPackage`", "/home/johu/temp/barPackage.m"]
bar[b]
top[b]
$ContextPath[[;; 2]]
This is bar! This is foo! Private`bar[] {"barPackage`", "fooPackage`"}
My question is how to avoid this shadowing or what would be the cleanest workaround?
Perhaps you can also explain, why in the first case does it even make a name for local symbol Private`foo[]? It is never defined.
Here are some references to relevant educational sources, which however did not solve my confusion
mainPackage&helperPackageissue. Solution 2 from the referred is the most acceptable one. I guess I should accept theduplicate tagthen? – Johu Jun 13 '15 at 17:24