How can you introduce a package, so that it is listed in $Packages
, without adding it to $ContextPath
?
Note that this question is concerned with defining a package when evaluating code, e.g. through evaluating a cell, rather than loading a package from a file.
This is useful if you want to add capabilities without introducing new "bare" symbols in any way -- they live in their own context and must be referenced through an explicit context, unless the user adds that context back to the context path.
Block[{$ContextPath}, Needs["Combinatorica`"]]
because the package is defined in a notebook, and it must be in multiple, separate input lines (therefore can't be wrapped)?BeginPackage
affects parsing, so it takes effect only starting with the next input. $\endgroup$Block
, it becomes a single input that is parsed beforeBeginPackage
is evaluated and changes the context. So while it may appear to work on first try, the package symbols will all be created in the Global context. $\endgroup$