Message Boards Message Boards

Avoid "Protected, Locked , Private package" warnings from this code?

Posted 9 years ago

Hello, I am trying to develop a CDF application using package in order to encode the contents. I do the development in stages; first .nb file of the code. After that I create the package from nb file by simply copy-paste the .nb file between

 BeginPackage["INT1D`"];
    Begin["`Private`"];
.
.
My code copied and pasted from .nb
End[];
SetAttributes[{all my functions},{ReadProtected,Protected,Locked}];
EndPackage[];

And from a nb file

Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
    "INT1D.wl"}]];
u =  z^2 Sin[4 \[Pi] z]^3;
xL = 0; xR = 1; nprecision = 20; nd = 16; fp = False;
INT1D`D1[u, xL, xR, nprecision, nd, fp];

In this setup I do not get any output from my code unless I remove Begin["Private"]; and corresponding End[]. Once I remove those I do get an output.

And no matter with or without Begin["Private"]; command I get warnings about my Functions are being D1 in D1[u, xL, xR, nprecision, nd, fp] is Protected Symbol D1 is locked. I get these messages for all my functions.

I dont see what I am doing wrong in here. I would appreciate it if anyone can point out my mistake.

Thanks

Erdem

POSTED BY: Erdem Uguz
2 Replies
Posted 9 years ago

Thank you for the reply. I created an example that mimics my actual problem in terms of the structure of the package. Here I used Private command without a problem. That is why I am little confused.

Here is that example.

Get[FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
    "TFPackageSourceCodedifference.wl"}]];
Manipulate[
 DynamicModule[{f = Sin[x], xR = 1, xL = 0, 
   Res = 0.4596976941318603`16, NRes = 0.4596976941318603`16}, 
  Column[{Row[{"Lower Limit ", InputField[Dynamic[xL], Number]}, 
     Spacer[5]], 
    Row[{"Upper Limit ", InputField[Dynamic[xR], Number]}, Spacer[5]],
     Row[{"Function  ", InputField[Dynamic[f]]}, Spacer[20]], 
    Button[Style["Calculate", Green, Bold], 
     Dynamic[Res = 
        TFPackageSourceCodedifference`WD1Int[f, xR, xL, np, nw];]], 
    Dynamic[NRes = 
       TFPackageSourceCodedifference`ND1Int[f, xR, xL, nw, np];], 
    Row[{"Result", InputField[Dynamic[Res], Enabled -> False]}, 
     Spacer[51]], 
    Row[{"Symbolic", 
      InputField[Dynamic[NRes[[1]]], Enabled -> False]}, Spacer[35]],
    Row[{"Difference", 
      InputField[Dynamic[NRes[[2]]], Enabled -> False]}, Spacer[35]]
    }]], {{np, 16, "NumberFormat"}, 
  ControlPlacement -> Bottom}, {{nw, 16, "WorkingPrecision"}, 
  ControlPlacement -> Bottom}, 
 Initialization :> (Get[
     FileNameJoin[{NotebookDirectory[EvaluationNotebook[]], 
       "TFPackageSourceCodedifference.wl"}]];)]

and the package

BeginPackage["TFPackageSourceCodedifference`"];
WD1Int::usage="";
ND1Int::usage="";
Clear[Global`x];
Begin["`Private`"];
WD1Int[f_,xR_,xL_,np_,nw_]:=Module[{xLcheck,xRcheck},xLcheck=NumberQ[xL];
xRcheck=NumberQ[xR];
If[xLcheck==True&&xRcheck==True,ResultTF=SetPrecision[NIntegrate[f,{Global`x,xL,xR},WorkingPrecision->Re[IntegerPart[nw]]],Re[IntegerPart[np]]],"Enter numeric inputs for Lower and Upper Limits"];
Return[ResultTF]];
ND1Int[f_,xR_,xL_,nw_,np_]:=Module[{xLcheck,xRcheck},xLcheck=NumberQ[xL];
xRcheck=NumberQ[xR];
numintwolf=WD1Int[f,xR,xL,np,nw];

If[xLcheck==True&&xRcheck==True,
ResultTFSym=SetAccuracy[Integrate[f,{Global`x,xL,xR}],nw];
DifferenceSymNum=ResultTFSym-numintwolf;

,"Enter numeric inputs for Lower and Upper Limits"];
Return[{ResultTFSym,DifferenceSymNum}]];

End[];
SetAttributes[{WD1Int,ND1Int},{ReadProtected,Protected,Locked}];
EndPackage[];

I dont know why using private does not create a problem without introducing the variable as you mentioned.

Erdem

POSTED BY: Erdem Uguz

You need to export symbols to INT1D` context by mentioning them between BeginPackage and Package. Otherwise everything is created in INT1D`Private` which will not be on $ContextPath.

You can read more in

http://reference.wolfram.com/language/tutorial/SettingUpWolframLanguagePackages.html

and related tutorials or

http://mathematica.stackexchange.com/questions/29324/creating-mathematica-packages

POSTED BY: Kuba Podkalicki
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract