Message Boards Message Boards

1
|
6532 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Package organization in a Wolfram Language application

I have watched the Video "Creating Documentation with Wolfram Workbench" several times, but there are some things I still don't understand. In discussion of recommended package organization for large projects it suggests the main .m | .wl file look like:

(* Wolfram Language Package *) BeginPackage["GoodStuff"] Get["GoodStuffSubPackage1"] Get["GoodStuffSubPackage2"] ... EndPackage[]

The subfile SubPackage2.m (in the same folder as GoodStuff.m) should look like:

(* Wolfram Language Package *) foo::usage="foo[] is a function that does nothing wrong because it does nothing." Unprotect[foo] Begin["Private``"] foo[___]:=Null End[] SetAttributes[foo,{Protected}]

Here is the issue: suppose SubPackage1 wants to use the function foo defined in SubPackage2. If I The usage message in SubPackage2 will not be encountered before the invocation of foo in SP1, and will thus create a symbol GoodStuff``Private``foo. What is the proper way to handle such a situation? Should I create a file AllUsageMessages.m and read it in before SP1 and SP2? It might be suggested that one should not use symbols before their containing file is read, but I think sometimes you need subsets that contain functions defined in each other. [Please forgive the " ' `" - I am new to this system...]

POSTED BY: Stephen Wandzura
2 Replies

One way to tackle this is to put all usage messages in the main package file, and then spread the implementation out in different subpackages. So just change what you have to

(* Wolfram Language Package *)
BeginPackage["GoodStuff`"]
    foo::usage = "foo[] is a function that does nothing wrong because it does nothing."
    bar::usage = "bar[] is another function"
    ....

    Get["GoodStuffSubPackage1"](* implements bar, can reference foo *)
    Get["GoodStuffSubPackage2"](* implements foo *)
          ...
EndPackage[]
POSTED BY: Jason Biggs

Yes, thank you - I understand. This is nearly the same as my idea to Get["GoodStuff``AllUsageMessages"]`

POSTED BY: Stephen Wandzura
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