Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

The rules described above explain why the standard application directory structure is as described herehere. There is nothing strictly enforcing this particular structure, but the system is designed in a way that it expects to find this structure in any package.

  • Looks on $Path for foo.m, foo.wl, foo.mx or directory foo
  • If a paclet declares the context foo` in its Kernel extension, it translates to the corresponding Root directory: See PacletInfo.m documentation project, Kernel extension section.

The rules described above explain why the standard application directory structure is as described here. There is nothing strictly enforcing this particular structure, but the system is designed in a way that it expects to find this structure in any package.

  • Looks on $Path for foo.m, foo.wl, foo.mx or directory foo
  • If a paclet declares the context foo` in its Kernel extension, it translates to the corresponding Root directory: See PacletInfo.m documentation project, Kernel extension section.

The rules described above explain why the standard application directory structure is as described here. There is nothing strictly enforcing this particular structure, but the system is designed in a way that it expects to find this structure in any package.

Fix small detail: `Needs::nocont` is emitted when needed context is not in `$Packages` after file loading.
Source Link
jkuczm
  • 15.1k
  • 2
  • 54
  • 85

However, Needs is different from Get in that it expects the context passed to it to appear in $ContextPath$Packages after the package has been loaded. This is why one needs to use BeginPackage and not merely Begin when writing a package. BeginPackage will permanently add that context both to $ContextPath and $Packages$Packages. Needs uses $Packages to determine if a package has already been loaded and avoid double-loading.

However, Needs is different from Get in that it expects the context passed to it to appear in $ContextPath after the package has been loaded. This is why one needs to use BeginPackage and not merely Begin when writing a package. BeginPackage will permanently add that context both to $ContextPath and $Packages. Needs uses $Packages to determine if a package has already been loaded and avoid double-loading.

However, Needs is different from Get in that it expects the context passed to it to appear in $Packages after the package has been loaded. This is why one needs to use BeginPackage and not merely Begin when writing a package. BeginPackage will permanently add that context both to $ContextPath and $Packages. Needs uses $Packages to determine if a package has already been loaded and avoid double-loading.

added 187 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k

However, Needs is different from Get in that it expects the context passed to it to appear in $ContextPath after the package has been loaded. This is why one needs to use BeginPackage and not merely Begin when writing a package. BeginPackage will alsopermanently add that context both to $Packages$ContextPath and $Packages. Needs uses $Packages to determine if a package has already been loaded and avoid double-loading.

(Something interesting: BeginPackage also updates Internal`$PackageDependencies based on its second argument. I do not know where this is used.)

In short, the file namesfile names and the contextcontext of a package doesn'tdon't strictly need to be the same. But if it isn'tthey aren't, Mathematica will sometimes get confused.

All theThe rules described above explain why the standard application directory structure is as described here. There is nothing strictly enforcing this particular structure, but the system is designed in a way that it expects to find this structure in any package.


Some interesting undocumented variables:

  • Internal`$PackageDependencies is updated by BeginPackage based on its second argument

  • $LoadedFiles is updated by Get. To get a more useful list, use Select[$LoadedFiles, Not@StringStartsQ[#, $InstallationDirectory] &]

However, Needs is different from Get in that it expects the context passed to it to appear in $ContextPath after the package has been loaded. This is why one needs to use BeginPackage and not merely Begin when writing a package. BeginPackage will also add that context to $Packages. Needs uses $Packages to determine if a package has already been loaded and avoid double-loading.

(Something interesting: BeginPackage also updates Internal`$PackageDependencies based on its second argument. I do not know where this is used.)

In short, the file names and the context of a package doesn't strictly need to be the same. But if it isn't, Mathematica will get confused.

All the rules above explain why the standard application directory structure is as described here. There is nothing strictly enforcing this particular structure, but the system is designed in a way that it expects to find structure in any package.

However, Needs is different from Get in that it expects the context passed to it to appear in $ContextPath after the package has been loaded. This is why one needs to use BeginPackage and not merely Begin when writing a package. BeginPackage will permanently add that context both to $ContextPath and $Packages. Needs uses $Packages to determine if a package has already been loaded and avoid double-loading.

In short, the file names and the context of a package don't strictly need to be the same. But if they aren't, Mathematica will sometimes get confused.

The rules described above explain why the standard application directory structure is as described here. There is nothing strictly enforcing this particular structure, but the system is designed in a way that it expects to find this structure in any package.


Some interesting undocumented variables:

  • Internal`$PackageDependencies is updated by BeginPackage based on its second argument

  • $LoadedFiles is updated by Get. To get a more useful list, use Select[$LoadedFiles, Not@StringStartsQ[#, $InstallationDirectory] &]

added 169 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading
added 169 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading
added 169 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading
added 169 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading
added 221 characters in body
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading
Source Link
Szabolcs
  • 236.5k
  • 31
  • 641
  • 1.3k
Loading