# Can a Mathematica Application be inside another Application?

The file structure of a simple MMA Application can have the form:

  MyApplication
MyApplication.m
SomeAuxiliarPack.m
Kernel
init.m


Where init.m file have the form:

Get["MyApplicationMyApplication"]
Get["MyApplicationSomeAuxiliarPack"]


Ok.. all nice until here.

The question is. How can I have a SubApplication inside Application, in some way that the SubApplication is independent from the first one, and is initialized together with MyApplication?

Using this structure:

  MyApplication
MyApplication.m
Kernel
init.m
MySubApplication
MySubApplication.m
Kernel
init.m


with init.m Application as:

Get["MyApplicationMyApplication"]
Get["MyApplicationMySubApplication"]
Get["MyApplicationSomeAuxiliarPack"]


and init.m SubApplication 2 as:

Get["MyApplicationMySubApplicationMySubApplication"]


It works, but as you can see, SubApplication init.m has a unnecessary reference for MyApplication.

(I felt this was similar to the issues you have been having and deserved something slightly more then a comment. This isn't exactly an answer, but I am hopeful to find one. Please comment if you have any questions or believe it should be pushed to a comment. ) First in init.m I have started to define function definitions in init.nb precisely like the following.

Get[FileNameSplit[If[$InputFileName=="",NotebookFileName[],$InputFileName]][[-3]] <> "MyApplication"]


Preferably putting the following into init.m will import all .m files in the main directory.

SetDirectory[
FileNameJoin@
Drop[FileNameSplit@
If[$InputFileName == "", NotebookFileName[],$InputFileName], -2]];
Map[Get[FileNameSplit[
If[$InputFileName == "", NotebookFileName[],$InputFileName]][[-3]] <> "" <>
FileBaseName@# <> ""] &,
DeleteCases[FileNames["*.m"], "PacletInfo.m"]];


And MyApplication.m would contain the following.

BeginPackage[
FileNameSplit[If[$InputFileName=="",NotebookFileName[],$InputFileName]][[-2]] <> "MyApplication"]
(* data *)
EndPackage[]


This allows you to simply copy and paste and rename the directory to effectively create a new package.

Now you probably could read back up the directory to determine if the directory above has a Kernel` directory to successfully generalize and solve the problem above. I would probably package such into into its own package because it would probably be longer then one line. If you did this I would advise linking to this documentation.