Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 2
    $\begingroup$ You can Needs["mypkg`sub`"] after BeginPackage of the main package. Or have nested BeginPackages if all of them export to your common context. There is a lot of discussion in 176434 but I think that thread misses simple approach. Start reading from Ronald Monson answer, then b3m2a1's and then the rest. $\endgroup$ Commented Jul 31, 2019 at 9:42
  • 1
    $\begingroup$ Note that you will not be able to prevent the user from calling a function using its full name, e.g. mypkg`sub`private`foo[1] will always work. As for your problem: I think the problem is the following: You first Get mypkg`mypkg, which declares the symbol mypkg`sub`foo. After this, you Get mypkg`sub, which now sees this symbol on the $ContextPath, which is why the definition inside the Private` context is still attached to the "public" symbol. In short, your exporting statement is the call in mypkg` . $\endgroup$ Commented Jul 31, 2019 at 11:06
  • $\begingroup$ Nasser, what @LukasLang states is correct, I find it analogous to the way in which we are able to call undocumented functions such as ones directly to the systems or otherwise. I usually wrap my overarching functions in an option defining wrapper, this allows me to bundle a number of them together for the functionality you wish to receive. However, I, too, have only used single package files, and am only beginning to investigate the multiple package method. $\endgroup$ Commented Jul 31, 2019 at 14:56
  • $\begingroup$ For which purpose do you want to hide these symbols? $\endgroup$ Commented Jul 31, 2019 at 20:00
  • $\begingroup$ @Shadowray For which purpose do you want to hide these symbols? that is the whole purpose of data and implementation hiding. So that your are free to modify them later as you wish without breaking client code. If Client to your package had access to your package private data and functions, and written code based on these, then if you later change the private data or the private functions API, then the client application will no longer work when you release new version of the package. $\endgroup$ Commented Jul 31, 2019 at 22:45