I am learning the new package style as current one is not working for me. I know it is probably not a good idea to use something with no official Wolfram documentation and not officially released. But I was just trying it out for now.
I'd like to make top level package with public API's and number of lower level subpackages each to process each API. But I want the name of the API in top level to be same as in subpackages.
The new package style is supposed to allow this from the references below.
In this new setup, I have this layout
C:\Users\Owner\AppData\Roaming\Mathematica\Applications\nma nma.m dsolveMGR.m The top level package is nma.m and since it is the same name as folder, then kernel/init.m is not needed (but it can also be there).
dsolveMGR is supposed to be a subpackage of nma
Both packages loads OK using
<<nma` from anywhere.
Now here is the problem. I have one public API in nma.m which is called dsolve[....] and inside this function I want to call the subpackage dsolveMGR for more processing.
But the function there is also called dsolve[].
This is supposed to work in the new style packages.
But eveything I tried is not working. When I call the public API dsolve[], the call bypasses the dsolve in nma.m and goes directly to dsolverMGR dsolve instead. It means the dsolve in the subpackage has overwritten the dsolve in the main top level package.
Here is complete code
nma.m file
Package["nma`"] Print["nma.m loaded"] PackageExport["dsolve"] (*so that user can call this from outside*) dsolve[ode_]:= Module[{}, Print["In nma`dsolve. Before calling nma`dsolveMGR`dsolve"]; (*now need to my own internal dsolve function to process more. *) (*nma`PackageScope`dsolveMGR`dsolve[ode]*) (*nma`dsolveMGR`PackagePrivate`dsolve[ode]*) nma`PackageScope`dsolve[ode] ] file dsolverMGR.m
(* It might look strange to just say Package["nma`"] below in the subpackage nma`dsolverMGR` but this is how it works. See example in first reference below. Mathematica sees this file in the nma folder and automatically makes it subpackage, at least this is my understanding *) Package["nma`"] Print["dsolveMGR.m loaded"] (*PackageScope["dsolve"]*) (*not sure if I need to do anything more here *) dsolve[ode_]:=Module[{}, Print["in nma`dsolveMGR`dsolve[] to do the actual processing..."] ] Using example
Now from a notebook, I do the following from clean kernel
<< nma` And see
nma.m loaded dsolveMGR.m loaded So both files are read OK automatically. Mathematica always loads nma.m first since that is the same as name of the folder. Then the rest are loaded. I only have one subpackage now but will be adding more if this set up works.
The problem comes now when making this call from the notebook:
nma`dsolve[y'[x] == Sin[x]] Gives
in nma`dsolveMGR`dsolve[] to do the actual processing... You see? top level dsolve was overwritten. I was expecting to see
In nma`dsolve. Before calling nma`dsolveMGR`dsolve in nma`dsolveMGR`dsolve[] to do the actual processing... Question is: How to see the above and not have dsolve in subpackage overwrite the dsolve in the top level package? I know ofcourse I can rename dsolve function in the subpackage. But this should not be needed. Each lives in its own package space, so one should be able to have same name in different packages.
I tried and tried and gave up. My limit on trying is 2 hrs. I learn better by examples, and not able to find one single example on the net showing this. I see many discussions but no examples.
V14
References
https://yuluyan.com/posts/mma-package/
What to be aware when using new-style package?