Maple Repositories - Maple Programming Help

Home : Support : Online Help : System : Libraries and Packages : repository

Maple Repositories

 • Any number of Maple procedures, modules and other data can be stored together to form a library.

Repository Files

 • Maple libraries are stored either as a single .mla file or in a collection of two files (with the filename extensions .lib and .ind). The single file (for example, MyLib.mla) or two files (for example, MyLib.lib and MyLib.ind) are called a repository. The term library and the more accurate term repository are sometimes used interchangeably.
 There can be more than one repository in a single directory.
 The .lib file is where most of the data associated with a repository is stored. The .ind file is an index file that Maple uses to locate items in the repository. An .mla file combines both the index and data. The first 1024 bytes of a .lib or .mla file is the header that Maple uses to store repository attributes such as READONLY/WRITABLE mode and lookup priority (see march). This header also maintains other information such as unique numeric identifier for anonymous members and top-level names in the repository (see below). If using a .lib and .ind repository, both files must be present for Maple to use the repository.
 To make a repository accessible to Maple, ensure that the directory in which it resides, or the full path and .lib or .mla filename are included in the global variable libname. This can be done by setting its value explicitly within Maple, or via the -b directory command-line option supported by batch-oriented user interfaces.  The contents of a repository are automatically assigned once it is referred to by libname.

Repository Members

 • A repository consists of any number of data objects called members. Each member is a Maple expression encoded in a compact and email safe internal format. The internal format is not publicly documented and may change between releases of the Maple software.

Manipulating Repositories

 • A Maple repository can be manipulated in various ways by using the built-in march command. Using march, you can create and list a repository, compact it or re-index it. For details on how these operations are performed, see march.
 Once you have created a repository, you can add new members to it by assigning the expression to be saved to a name, and then calling the procedure savelib with the names to be saved as arguments. The names under which the expressions are saved are used to identify the expressions in the repository. Saving an expression to a repository may involve the creation of other, anonymous repository members as well.

Examples

This example illustrates some typical manipulations of repositories in Maple.

Make a temporary workspace.

 > $\mathrm{repo}≔"/tmp/repo":$
 > $\mathrm{mkdir}\left(\mathrm{repo}\right):$
 > $\mathrm{startdir}≔\mathrm{currentdir}\left(\mathrm{repo}\right):$

Define a utility to print an abbreviated repository listing.

 > $\mathrm{listrep}≔r→\mathrm{map2}\left(\mathrm{op},1,\mathrm{march}\left('\mathrm{list}',r\right)\right):$

Create an empty repository.

 > $\mathrm{march}\left('\mathrm{create}',"./MyLib.mla",100\right):$
 > $\mathrm{listrep}\left("./MyLib.mla"\right)$
 $\left[{}\right]$ (1)

Create an expression to be stored in our empty repository. A typical Maple package has a structure similar to, but is much larger than this. (In practice, its definition is read from a source file, not entered inline.)

 > $m≔\mathbf{module}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{export}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}a,b;\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}a≔x→x^2;\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}b≔x→x^3\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module}:$

Ensure that savelib places m in the correct repository.

 > $\mathrm{savelibname}≔".":$$\mathrm{libname}≔\mathrm{savelibname},\mathrm{libname}:$
 > $\mathrm{savelib}\left('m'\right):$

The listing of the repository now shows that the repository contains not only m, but also two anonymous members that have been given the numeric references 1 and 2.

 > $\mathrm{listrep}\left("./MyLib.mla"\right)$
 $\left[{":-1.m"}{,}{"m.m"}{,}{":-2.m"}\right]$ (2)

The header of the maple.mla file contains the next available numeric identifier for the repository and is updated whenever something is saved to the repository that has no global name.

 > u := proc() local L; proc(x) L - x end end():
 > $\mathrm{savelib}\left('u'\right):$
 > $\mathrm{listrep}\left("./MyLib.lib"\right)$
 $\left[{":-3.m"}{,}{"u.m"}{,}{":-1.m"}{,}{"m.m"}{,}{":-2.m"}\right]$ (3)

Clean up.

 > $\mathrm{fremove}\left("MyLib.lib"\right):$
 > $\mathrm{currentdir}\left(\mathrm{startdir}\right):$
 > $\mathrm{rmdir}\left(\mathrm{repo}\right):$