I am trying to define two different packages that process some information in a different way. These packages have functions into them with optional arguments. The names of the optional arguments happen to collide and Mathematica is complaining about shadowing of these symbols. Here is an example of my code:
BeginPackage["MyPackage1`"]
Options[f] = {a -> 1, b -> 2};
f[OptionsPattern[]] := {OptionValue[a], OptionValue[b]};
EndPackage[]
BeginPackage["MyPackage2`"]
Options[g] = {a -> 1, b -> 2};
g[OptionsPattern[]] := {OptionValue[a], OptionValue[b]};
EndPackage[]
Mathematica complains:
"Symbol "a" appears in multiple contexts ({"MyPackage2`", "MyPackage1`"}); definitions in context "MyPackage2`" may shadow or be shadowed by other definitions."
Now I try:
Needs["MyPackage1`"]
Needs["MyPackage2`"]
f[a -> 3, b -> 4]
g[a -> 1, b -> 2]
(* {3,4} {1,2} *)
Thus, the functions work correctly as they are supposed to, but Mathematica is insisting on coloring a
and b
in red everywhere and that they appear in different contexts.
Is there a way to solve this problem? (without renaming a
and b
as they represent the same input data in the two packages, would be non-intuitive to change their names).
Common`
context. $\endgroup$ – J. M.'s ennui♦ May 29 '15 at 3:34?
to learn more about them without having to refer to the docs. $\endgroup$ – J. M.'s ennui♦ May 29 '15 at 3:51Common
context is many times necessary. $\endgroup$ – FJRA May 29 '15 at 3:57BeginPackage
and name the contextcommon`
for example. But then, how do I refer to the symbols in the arguments?Common`
even in the function options definition? Or just use them directly? Thanks! $\endgroup$ – Bichoy May 29 '15 at 4:09