Implementing Packages using Modules - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Programming : Modules : Writing Packages : module/package

Implementing Packages using Modules



One easy application of modules is the implementation of packages. A "package" is simply a collection of routines (and perhaps other data) that are collected together in some way. Typically, a package provides a range of functionality for solving problems in some well-defined problem domain. The scope of a package may be quite wide or very small. What is appropriate is up to you, as the author.


Many functional subsets of the Maple library are presented to the user as packages. For example, Maple has packages for group theory (the GroupTheory and group packages), for geometry (the geometry and geom3d packages), for number theory (numtheory), and for linear algebra (LinearAlgebra and Student[LinearAlgebra]). New packages are being written as modules, but a few packages use the old table-based implementation.


To create a package by using modules, simply list the names of the routines that you want to make available to your users as exports of a module. Include the definitions of your exported ("public") routines in the module definition, and assign the resulting module to the name of your package.


Modules that are used as packages must include the option package among their options. Package exports are automatically protected, and are able to be bound persistently in an interactive session by using the with command.


You may prevent users from tampering with sensitive internal data used in your routines by making the data private to the package. This is done by using local (not exported) variables of the module that implements your package.


To save your package (or any other module) to a Maple repository, ensure that the directory containing the repository is the first one listed in the global variable libname, or assign the global variable savelibname the name (as a string) of the directory holding your repository. Then call the procedure savelib with the name of your package as its sole argument. This saves a copy of your package to the repository. Any Maple session that includes the same directory in the global variable libname will then be able to access the package by name.


For more information on making packages, see the Writing Packages chapter of the Maple Programming Guide.


For more information on Maple repositories, see repository and march.


This example assumes that you have a writable repository listed in the global variable libname.

MyPackage := module()
    export    f1, f2;
    local    loc1;
    option package;
    f1 := proc() loc1 end proc;
    f2 := proc( v ) loc1 := v end proc;
    loc1 := 2;
end module:




See Also

march, module, procedure, ProgrammingGuide/WritingPackages, repository, repository/management

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam