Reference Guides » Undocumented Contexts

Package

The "Package`" context drives the new-style package system. It's functions are:

DeclarePackage

Declares a package to be loaded by the autoload mechanism. It's called like

 Package`DeclareLoad[
  {syms...},
  context,
  ops
  ]

Where it takes as options

  • HiddenImport whether or not to expose the context after loading ( False by default)
  • Path the path to use when finding the context file
  • HiddenContexts apparently unused?
  • ExportedContexts apparently unused?

Here' an example with the "Macros`" package:

 Package`DeclareLoad[
  {
    "Macros`SetArgumentCount",
    "Macros`$FailRHS"
    },
  "Macros`",
  Package`HiddenImport->True
  ]

Then the autoloading was configured on all these packages:

 Macros`SetArgumentCount//OwnValues
 {HoldPattern[Macros`SetArgumentCount]:>Package`ActivateLoad[Macros`SetArgumentCount,{Macros`$FailRHS,Macros`SetArgumentCount},"Macros`",{Package`HiddenImport->True,Path->Automatic}]}

But if we let the autoloader work the OwnValues are cleared:

 Macros`SetArgumentCount
Macros`SetArgumentCount//OwnValues
 {}

ActivateLoad

Used by DeclaredLoad to auto-load the package. Called like

 Package`ActivateLoad[sym,
  {pkgSyms...},
  context,
  ops
  ]

As options it takes

  • HiddenImport whether or not to expose the context after loading ( False by default)
  • Path the path to use when finding the context file

PackageInformation

Extracts package info for a package declared in this new style:

 Package`PackageInformation["NumericArrayUtilities`"]//Keys
 {"PackageExports","PackageFragments"}

If a package hasn't been loaded it throws an error:

 Package`PackageInformation["CacheManager`"]
Package`PackageInformation::nonpack: -- Message text not found -- ("CacheManager`")

This can be quieted by setting Package`ForceLoad to False :

 Package`PackageInformation["CacheManager`", Package`ForceLoad->False]

If the package is loaded it works again:

 Block[{$ContextPath={"System`"}}, <<CacheManager`];
Package`PackageInformation[
  "CacheManager`", 
  Package`ForceLoad->False
  ]~Lookup~"PackageExports"
 HoldComplete[CacheManager`CacheData,CacheManager`$DefaultCacheMethod,CacheManager`$DefaultCacheSize,CacheManager`CacheSize,CacheManager`CacheSymbolQ,CacheManager`$Caches,CacheManager`GetCache,CacheManager`CreateCache,CacheManager`RemoveCache,CacheManager`CacheGet,CacheManager`CacheSet,CacheManager`CacheUnset,CacheManager`CacheKeys,CacheManager`iKeys,CacheManager`CacheInformation,CacheManager`makeCacheSymbol,CacheManager`makeCacheFile,CacheManager`CacheDirectory,$CacheBaseDirectory,CacheManager`$FlushInterval,CacheManager`$AllowAutoFlushing,CacheManager`CacheDirtyQ,CacheManager`CacheDirtiness,CacheManager`FlushCacheDeferred,CacheManager`FlushDirtyCaches,CacheManager`FlushCache,CacheManager`SpillCache,CacheManager`CachedExpression,CacheManager`CachedFunction,CacheManager`CachedMap]

LoadPackage

Not entirely clear how this works. Ought to do the actual work of loading the package, but can't figure out what actually changes after using it.

CreatePackageCache

Creates a .mx cache of a package for optimized loading, but I can't remember how exactly this works. Is prone to crashing kernels without a destination directory or throwing cascades of errors.

See Also: