Book contents
- Frontmatter
- 1 An introduction to Mathematica
- 2 The Mathematica language
- 3 Lists
- 4 Functional programming
- 5 Procedural programming
- 6 Rule-based programming
- 7 Recursion
- 8 Numerics
- 9 Graphics programming
- 10 Front end programming
- 11 Examples and applications
- 12 Writing packages
- Appendix A How expressions are evaluated
- Appendix B Debugging
- References
- Solutions to exercises
- Index
12 - Writing packages
Published online by Cambridge University Press: 21 March 2011
- Frontmatter
- 1 An introduction to Mathematica
- 2 The Mathematica language
- 3 Lists
- 4 Functional programming
- 5 Procedural programming
- 6 Rule-based programming
- 7 Recursion
- 8 Numerics
- 9 Graphics programming
- 10 Front end programming
- 11 Examples and applications
- 12 Writing packages
- Appendix A How expressions are evaluated
- Appendix B Debugging
- References
- Solutions to exercises
- Index
Summary
Packages are text files that contain Mathematica commands. They are designed to make it easy to distribute your programs to others, but they also provide a mechanism for you to write programs that integrate with Mathematica in a seamless manner. In this chapter we will discuss the organization and creation of packages including a discussion of contexts, which are a mechanism for organizing new names and symbols in your Mathematica sessions.
Introduction
When you begin 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. In principle, the only difference between those files and the ones you create is that those were written by professional programmers. There is another difference: the definitions in those files are placed in special structures called packages. Indeed, these files themselves are often called “packages” instead of “files.”
Packages are a name localizing construct, analogous to Module, but for entire files of definitions. Their purpose is to allow the programmer to define a collection of functions for export. These exported functions are for the users of the package to 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.
In this chapter, you will learn how to write your own packages.
- Type
- Chapter
- Information
- An Introduction to Programming with Mathematica® , pp. 395 - 416Publisher: Cambridge University PressPrint publication year: 2005