Message Boards Message Boards

0
|
4900 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

[?] Use a package with an association inside it?

Posted 7 years ago

I build a package and define an association inside it. When I call it from notebook I get an error that key not exist.

Get["C:\\MATHEMATICA\\package\\packageStruct.m"];
kk = PK["gigi", {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}];
kk[face]
Missing["KeyAbsent", face]

and this it's my package file packageStruct.m;

BeginPackage["packageStruct`"]
PK::usage = "pk=PK[n,vert,face,adjv,adjf]";
Begin["`Private`"]

PK[name_,vertM_,faceM_,adjvertM_,adjfaceM_]:=<|n->name, vert->vertM, face->faceM, adjv->adjvertM,adjf->adjfaceM|>;
End[]
EndPackage[]

Thanks in advance.

POSTED BY: Alessio Alessio

Better use string keys. "vert" instead of vert, it does not work because the vert from the package is really packageStruct`Private`vert.

You could also export keys' symbols next to PK but existance of e.g. vert before Get will cause shadowing problems.

See more in: Derivative from my package function returns 0

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