This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Programming / Scoping  /
EndPackage

  • EndPackage[ ] restores $Context and $ContextPath to their values before the preceding BeginPackage, and prepends the current context to the list $ContextPath.
  • Every call to EndPackage must be balanced by an earlier call to BeginPackage.
  • EndPackage is typically used at the end of a Mathematica package.
  • EndPackage returns Null.
  • EndPackage resets the values of both $Context and $ContextPath.
  • See the Mathematica book: Section 2.6.10.

    Further Examples

    Nested BeginPackages and EndPackages behave properly. Here we have two nested context changes.

    In[1]:=

    Out[1]=

    The first EndPackage restores the context that was current before the last BeginPackage.

    In[2]:=

    Out[2]=

    Another EndPackage restores the original context.

    In[3]:=

    Out[3]=

    See also the Further Examples for BeginPackage.