Overview - Maple Help

export

the export declaration

 Calling Sequence export e1, e2, ...

Parameters

 e1, e2, ... - one or more (optionally typed and/or initialized) names to be exported

Description

 • The export clause in a module definition is used to "declare" one or more names that are to be made available to clients of the module once the module has been instantiated. The names are accessible outside the module definition by using the member selection operator :-. These names are called the "exports" of the module. Each of the expressions e1, e2, ... must be either a symbol, or an expression of the form symbol::type. An export declared as symbol::type effects a type assertion on the assigned value of the export.  If $\mathrm{kernelopts}\left(\mathrm{assertlevel}\right)$ is set to 2, assigning a value that does not match the declared type raises an exception.
 • The essential feature of the exports of a module is that they are local to the module; that is, they are not global names. The scope of an exported name is exactly the same as that of a local variable of the module. The primary difference is that an exported name is not private to the module. It is accessible even outside the definition of the module.
 • Exported names are unique to the execution of the module definition in which they are bound. A fresh set of exported names is created each time a module definition is executed (which is part of its evaluation).
 • Within the module, the evaluation rules for module exports are identical to those for module locals and to those for local variables in procedures. Outside of the module, exported names have the same evaluation rules as global variables. (See eval for details.)
 • The set of names exported by a module is fixed and is set at the time the module definition is evaluated. You cannot modify the set of exports of an instantiated module.
 • Names must be explicitly declared to be exported. A name cannot be resolved as an export by implicit scoping rules.
 • A module m may export a name s which is assigned a module, within the body of m. (In other words, s is a submodule of m.) The exports of the submodule s are accessible by first selecting the submodule s of m using $m:-s$, and then selecting an appropriate exported member e of s by $m:-s:-ⅇ$.

Examples

Declare some exported names.

 > $P≔\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(a,b,c\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}\mathbf{end module}$
 ${P}{≔}{\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}}{a}{,}{b}{,}{c}{;}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (1)

Now access them with the $:-$ operator.

 > $P:-a$
 ${a}$ (2)
 > $\mathrm{evalb}\left(a=P:-a\right)$
 ${\mathrm{false}}$ (3)
 > $\mathrm{unprotect}\left(P:-a\right);$$P:-a≔5$
 ${a}{≔}{5}$ (4)
 > $P:-a$
 ${5}$ (5)
 > $a$
 ${a}$ (6)
 > $\mathrm{with}\left(P\right)$
 $\left[{a}{,}{b}{,}{c}\right]$ (7)
 > $a$
 ${5}$ (8)

The visibility of exports is, in some sense, "transitive".

 > m := module()     export s, p;     s := module()         export e;         e := 2     end module;     p := proc()         s:-e     end proc end module:
 > $m:-s:-e$
 ${2}$ (9)
 > $m:-p\left(\right)$
 ${2}$ (10)

If either s is not exported from m, or e is not exported from s, then this does not work.

 > m := module()     export p;     local s;     s := module()         export e;         e := 2     end module;     p := proc()         s:-e     end proc end module:
 > $m:-s:-e$
 > $m:-p\left(\right)$
 ${2}$ (11)

Here, e is not even available inside the body of m.

 > m := module()     export p;     local s;     s := module()         local e;         e := 2     end module;     p := proc()         s:-e # error, not an export of s     end proc end module:
 > $m:-s:-e$
 > $m:-p\left(\right)$