Suppose we have the following package ABC.wl.
BeginPackage["ABC`"]
Begin["DEF`"]
f1 = 0;
f2[x_] := x + 1
End[]
EndPackage[]
Using the package from a notebook yields the following definitions.
Needs["ABC`"]
In[1]:= Definition[DEF`f1]
Out[1]= DEF`f1 = 0
In[2]:= Definition[DEF`f2]
Out[2]= DEF`f2[DEF`x_] := DEF`x + 1
How can DEF`* be "moved" to Global` such that the definitions are of the same form as if they were defined in Global`?
In[1]:= Definition[f1]
Out[1]= f1 = 0
In[2]:= Definition[f2]
Out[2]= f2[x_] := x + 1
Update Some motivation as requested by Szabolcs: this is useful e.g. when you want to print definitions from a context in a package without touching the source code of the package.
f1is present in both theABC`andGlobal`contexts. Do you really want to have the same symbol for different contexts? – J. M.'s missing motivation May 11 '20 at 14:35ABC`could be removed after the definitions have been moved toGlobal`to avoid the conflict. – Markus May 11 '20 at 14:41Block[{$ContextPath = {"System`", "DEF`"}}, Scan[(Context[#] = "Global`") &, Names["DEF`*"]]]. This will automatically makeDEF`context empty, and it will be then automatically removed from a lit of available contexts, as perContexts[]. – Leonid Shifrin May 11 '20 at 14:52