`export`
the export declaration
Calling Sequence
Parameters
Description
Examples
export e1, e2, ...
e1, e2, ...
-
one or more (optionally typed and/or initialized) names to be exported
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 kernelopts⁡assertlevel 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:−ⅇ.
Declare some exported names.
P ≔ moduleoptionpackage;_export⁡a,b,cend module
P ≔ moduleoptionpackage;exporta,b,c;end module
Now access them with the :− operator.
P:-a
a
evalb⁡a=P:-a
false
unprotect⁡P:-a;P:-a≔5
a≔5
5
with⁡P
a,b,c
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
m:-p⁡
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:
Error, module does not export `s`
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:
Error, (in p) module does not export `e`
See Also
kernelopts
local
module
module/package
Download Help Document