This is documentation for Mathematica 5, which was
based on an earlier version of the Wolfram Language.

 2.7.10 Setting Up Mathematica Packages In a typical Mathematica package, there are generally two kinds of new symbols that are introduced. The first kind are ones that you want to "export" for use outside the package. The second kind are ones that you want to use only internally within the package. You can distinguish these two kinds of symbols by putting them in different contexts. The usual convention is to put symbols intended for export in a context with a name Package` that corresponds to the name of the package. Whenever the package is read in, it adds this context to the context search path, so that the symbols in this context can be referred to by their short names. Symbols that are not intended for export, but are instead intended only for internal use within the package, are conventionally put into a context with the name Package`Private`. This context is not added to the context search path. As a result, the symbols in this context cannot be accessed except by giving their full names. Contexts conventionally used in Mathematica packages. There is a standard sequence of Mathematica commands that is typically used to set up the contexts in a package. These commands set the values of \$Context and \$ContextPath so that the new symbols which are introduced are created in the appropriate contexts. The standard sequence of context control commands in a package. BeginPackage["Collatz`"] Collatz::usage = "Collatz[n] gives a list of the iterates in the 3n+1 problem, starting from n. The conjecture is that this sequence always terminates." Begin["`Private`"] Collatz[1] := {1} Collatz[n_Integer] := Prepend[Collatz[3 n + 1], n] /; OddQ[n] && n > 0 Collatz[n_Integer] := Prepend[Collatz[n/2], n] /; EvenQ[n] && n > 0 End[ ] EndPackage[ ] The sample package Collatz.m. Defining usage messages at the beginning of a package is the standard way of making sure that symbols you want to export are created in the appropriate context. The way this works is that in defining these messages, the only symbols you mention are exactly the ones you want to export. These symbols are then created in the context Package`, which is then current. In the actual definitions of the functions in a package, there are typically many new symbols, introduced as parameters, temporary variables, and so on. The convention is to put all these symbols in the context Package`Private`, which is not put on the context search path when the package is read in. This reads in the sample package given above. In[1]:= <