Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Previous section-----Next section

2.12.5 Files for Packages

When you create or use Mathematica packages, you will often want to refer to files in a system-independent way. You can use contexts to do this.

The basic idea is that on every computer system there is a convention about how files corresponding to Mathematica contexts should be named. Then, when you refer to a file using a context, the particular version of Mathematica you are using converts the context name to the file name appropriate for the computer system you are on.

<<context` read in the file corresponding to the specified context

Using contexts to specify files.
This reads in one of the standard packages that come with Mathematica.

In[1]:=  <<Graphics`Colors`

name.mx file in DumpSave format
name.mx/$SystemID/name.mx file in DumpSave format for your computer system
name.m file in Mathematica source format
name/init.m initialization file for a particular directory
dir/... files in other directories specified by $Path

The typical sequence of files looked for by <<name`.

Mathematica is set up so that <<name` will automatically try to load the appropriate version of a file. It will first try to load a name.mx file that is optimized for your particular computer system. If it finds no such file, then it will try to load a name.m file containing ordinary system-independent Mathematica input.

If name is a directory, then Mathematica will try to load the initialization file init.m in that directory. The purpose of the init.m file is to provide a convenient way to set up Mathematica packages that involve many separate files. The idea is to allow you to give just the command <<name`, but then to load init.m to initialize the whole package, reading in whatever other files are necessary.

This reads in the file Graphics/init.m, which initializes all standard Mathematica graphics packages.

In[2]:=  <<Graphics`


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: