# Why the package (.wl) and .nb behaves completely different [duplicate]

I am developing an application in one part I am checking the if the functions are constant or not. I am using a couple of lines of code (it is possible that there is another way of doing it) but the code behaves differently when I use as a package instead of in a .nb file. The notebook code is

FunCons2[var1_, var2_, var3_, var4_] := Module[{fields}
, fields = Flatten[{var1, var2, var3, var4}]
; consz =  fields /. z -> {a, b}
; consz
]

f1 = 1;
f2 = t^3 + (z - 1) (z - 2) + E^-t Sin[z];
f3 = {-1 + E^-t Cos, 2 (1 + E^-t Cos)};
f4 = Limit[f2, t -> 0];

FunCons2[f1, f4, f3, f2]


The output as you can see t is replaced a and b

{  {1, 2 - 3 z + z^2 + Sin[z], {-1 + E^-a Cos, -1 + E^-b Cos},
{2 (1 + E^-a Cos), 2 (1 + E^-b Cos)},
{a^3 + (-2 + z) (-1 + z) + E^-a Sin[z], b^3 + (-2 + z) (-1 + z) + E^-b Sin[z]}}
}


and the package version is

Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]],"CheckCons.wl"}]];

f1 = 1;
f2 = t^3 + (z - 1) (z - 2) + E^-t Sin[z];
f3 = {-1 + E^-t Cos, 2 (1 + E^-t Cos)};
f4 = Limit[f2, t -> 0];
CheckConsFunCons[f1, f4, f3, f2]


The package

BeginPackage["CheckCons"];

FunCons::usage="";

Begin["Private"];

FunCons[var1_,var2_,var3_,var4_]:=Module[{fields,a,b},
fields=Flatten[{var1,var2,var3,var4}];
consz=fields/.z->{a,b};
consz
]

End[];

EndPackage[];


And the output is

{
{1, 2 - 3 z + z^2 + Sin[z], -1 + E^-t Cos, 2 (1 + E^-t Cos),
t^3 + (-2 + z) (-1 + z) + E^-t Sin[z]}
}


The problem is replacing z with a and b. Inside the package the code does not replace it. I don't know why or how to avoid that.

• The reason I am not really happy is still I am not understanding the reason why it is happening like this. If you look at the Print from the package for the fields. {1,2-3 z+z^2+Sin[z],-1+E^-t Cos,2 (1+E^-t Cos),t^3+(-2+z) (-1+z)+E^-t Sin[z]} t and z are still the variable no private or global why I can't replace t or z directly. Even when you look at the output of Variables[Level[fields,{-1‌​}]][] it is {} or z or t. – Erdem May 3 '17 at 18:15
• @Erdem clear the kernel, run the package and check ?? CheckConsFunCons. – Kuba May 3 '17 at 18:31
• @Kuba it is Attributes[FunCons]={Locked,Protected,ReadProtected}` – Erdem May 3 '17 at 20:32
• @Erdem Don't use it, there aren't any above. They are not needed. And without ReadProtected you will see that the definition uses Private symbols. – Kuba May 3 '17 at 20:34
• @Erdem I've put some edits to the linked question. Let me know if they helped. And please learn how to create minimal working examples. – Kuba May 4 '17 at 7:37