5

When writing a Mathematica package MyPackage, with functions f1, f2 and f3, one can use the template:

BeginPackage["MyPackage`"];

f1::usage = "f1[] ....";

f2::usage = "f2[] ....";

Begin["`Private`"];

f1[]:= code for f1

f2[]:= code for f2

f3[]:= code for f3 (not visible as only in the private context)

End[];

EndPackage[];

My question is linked to the structuration of package. In fact, instead of having a lot of functions in a package, i would like to build subpackages with this kind of structure.

MyPackage
   SubMyPackage1
       Function1
       Function2
   SubMyPackage2
       Function1
       Function2
       Function3
       Function3
...

Can you help me to define a robust template to make and use a package with different levels of subpackages ?

Thanks a lot for your help.

Bendesarts
  • 1,099
  • 5
  • 12

1 Answers1

3

You can set up such a hierarchy fairly easily.

One way is hinted at by the supplied packages (eg NumericalCalculus). Simply define your packages and Get[] them using a 'master' package.

A similar method is to ensure that all dependent packages are loaded with the package definition

BeginPackage["MyMain`Package`", {"MyMain`SecondPackage`","MyMain`ThirdPackage`""MyMain`FourthPackage`"}]

as required.

This question may be answered here.

dwa
  • 1,939
  • 14
  • 14