Overview - Maple Help

local

local variables of module

 Calling Sequence local loc1, loc2, ...

Parameters

 loc1, loc2, ... - one or more (optionally typed and/or initialized) local variable names

Description

 • 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 $\mathrm{::}$, 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.

Examples

 > m := module()     local loc1;     export setter, getter;     loc1 := 2;     getter := proc() loc1 end proc;     setter := proc( v ) loc1 := v end proc; end module:
 > $m:-\mathrm{getter}\left(\right)$
 ${2}$ (1)
 > $m:-\mathrm{loc1}$
 > $m:-\mathrm{setter}\left(5\right)$
 ${5}$ (2)
 > $m:-\mathrm{getter}\left(\right)$
 ${5}$ (3)