Module Options - Maple Help

Home : Support : Online Help : Programming : Modules : Module Options

Options for Modules

 Calling Sequence option opt1, opt2, ... options opt1, opt2, ...

Parameters

 opt1, opt2, ... - symbols or equations for options

Description

 • As with procedures, modules accept option declarations. An option is declared at the beginning of a module definition by the option declaration, which begins with the keyword option (or, equivalently, options) and is followed by an expression sequence of one or more options. Each option opt1, opt2, ... must either be a symbol or an equation whose left-hand side is a symbol.
 • An option whose meaning is not known to the system is ignored. This allows you to use options for your own purposes; they are equivalent to attributes and are accessible as such.
 • The only standard options that are meaningful for both procedures and modules are the trace and copyright options. In particular, the options remember, system, arrow, operator, and inline have no meaning for modules.
 • Only four options have a predefined meaning for modules. One is the module initialization option that takes the form load = pname, where pname is the name of a procedure found among the declared exports or locals of the module. If this option is present, then this procedure is called when the module is read from the Maple repository in which it is found.
 • Modules with option package are understood by the system to represent Maple packages. A module that is created with option package has its exports automatically protected.
 • The option record is used to identify records. Records are produced by the Record constructor and are represented using modules.
 • The unload = pname and load = lname options specifies the name of a local or exported procedure of the module that is to be called when the module is destroyed or loaded from a repository. These options mirror the functionality provided by the ModuleLoad and ModuleUnload commands.

Examples

 > $u≔\mathbf{module}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}...\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module}:$
 > $v≔\mathbf{module}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{_export}\left(e\right);\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{_local}\left(l\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module}:$
 > $\mathrm{interface}\left('\mathrm{verboseproc}'=1\right):$
 > $\mathrm{print}\left(u\right)$
 ${\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{export}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (1)
 > $\mathrm{print}\left(v\right)$
 ${\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{local}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{l}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{export}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (2)

This module is initialized by calling the procedure startup when the module is read from a repository. It executes the procedure shutdown when the module is either garbage collected or when Maple exits.

 > P := module()     export e;     local T, startup, shutdown;     option load = startup, unload = shutdown;     e := proc( n::posint )         if assigned( T[ n ] ) then             T[ n ]         else             int( expr, x )         end if     end proc;     startup := proc( )         # store common values         local    i, expr;         global  x;         for i from 1 to 100 do             expr := sin( n * x ) * cos( n * x );             T[ expr, x ] := int( expr, x )         end do     end proc:     shutdown := proc( )         # print a message         printf("Module P is going away\n");     end proc: end module:

This module has its exports protected automatically.

 > $m≔\mathbf{module}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{option}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{package};\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{_export}\left(e\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module}$
 ${m}{≔}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{option}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathrm{package}}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{export}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (3)
 > $\mathrm{type}\left(m:-e,'\mathrm{protected}'\right)$
 ${\mathrm{true}}$ (4)

Module exports are not protected in the absence of the package option.

 > $m≔\mathbf{module}\left(\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathrm{_export}\left(e\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module}$
 ${m}{≔}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{export}}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{e}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (5)
 > $\mathrm{type}\left(m:-e,'\mathrm{protected}'\right)$
 ${\mathrm{false}}$ (6)