Packages

Paul R. Wellin · Cambridge University Press eBooks · 2015

After you have developed several programs for some related tasks, you will find it convenient to group them together and make them available as a cohesive whole. Packages are designed to make it easy to distribute your programs to others, but they also provide a framework for you to write programs that integrate with Mathematica seamlessly. A package is simply a text file containing Mathematica code. Typically you put related functions in a package. So there might be a computational geometry package or a random walks package that includes functions in support of those tasks. The package framework includes a name-localizing construct, analogous to Module, but for entire files of definitions. The idea is to allow you, the programmer, to define a collection of functions for export. These exported functions are what the users of your package will work with and are often referred to as public functions. Other functions, those that are not for export, are auxiliary, or private functions, and are not intended to be accessible to users. The package framework, and contexts specifically, provide a convenient way to declare some functions public and others private. In this chapter we will describe this framework and show how to write, install, and use the packages developed with it. Working with packages Loading and using packages Upon starting a Mathematica session, the built-in functions are immediately available for you to use. There are, however, many more functions that you can access that reside in files supplied with Mathematica. The definitions in those files are placed in special structures called packages. Indeed, these files themselves are often called “packages” instead of “files.” Mathematica packages have been written for many different domains. They are provided with each version of Mathematica and are referred to as the Standard Extra Packages. Their documentation is available in the Documentation Center (under the Help menu) and they provide a good set of examples for learning about package creation and usage.

Read the paper · More papers on PaperTik