After running your Package code the first time
Test1`
is added to the$ContextPath
.When you call
Test1`function1[5]
the symbolfunction1
is created in the contextTest1`
After calling
BeginPackage["Test1`"]
andBegin["`Private`"]
the$ContextPath
is:{"Test1`","System`"}
When you use
function1
infunction1[x_] := x
it is found in the$ContextPath
and therefore it parses asTest1`function1
.
To avoid this, you need to either remove the symbol Test1`function1
from the context path before defining function1[x_] := x
, or you need to give the context explicitly. Either of these should work:
BeginPackage["Test1`"];
Begin["`Private`"];
Test1`Private`function1[x_] := x
End[];
EndPackage[];
Or:
BeginPackage["Test1`"];
Remove[function1]
Begin["`Private`"];
function1[x_] := x
End[];
EndPackage[];
If you wish to completely resentreset the contents of Test1`
every time the package is run you might use Remove["Test1`*"]
.