local variables of module
local loc1, loc2, ...
loc1, loc2, ...
one or more (optionally typed and/or initialized) local variable names
The beginning of a module definition may contain a declaration of one or more local variables. These are exactly analogous to local variables of procedures. Each expression loci must be either a symbol or an expression of type `::`, whose first operand (the variable name) is of type symbol. When a local variable is declared using ::, its type is checked whenever it is assigned to, as long as kernelopts( 'assertlevel' ) has a value that is at least 2.
Local variable bindings are visible in the body of the module definition in which they are declared, but not outside of it. An error results from an attempt to access a local variable of a module as though it were exported (using :− ).
Local variables are unique to the execution of the module definition in which they are bound. A fresh set of local variables is created each time a module definition is executed (which is part of its evaluation).
The evaluation rules for module local variables are identical to those of procedure locals. (See eval for details.)
You can provide controlled access to the local variables of a module by supplying exported members that may query or modify the value of a local. Note: Local variables can "escape" from modules just as they can escape from procedures, for example by returning an unevaluated local from an exported procedure.
Module locals can also be declared thread local by using the thread_local type modifier. This allows the variable to store a different value for each thread that accesses the module. This can be useful for making modules thread-safe.
m := module()
export setter, getter;
loc1 := 2;
getter := proc() loc1 end proc;
setter := proc( v ) loc1 := v end proc;
Error, module does not export `loc1`
Download Help Document
What kind of issue would you like to report? (Optional)