Overview - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


`local`

local variables of module

 

Calling Sequence

Parameters

Description

Examples

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 ::, 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:-getter

2

(1)

m:-loc1

Error, module does not export `loc1`

m:-setter5

5

(2)

m:-getter

5

(3)

See Also

local_scopes

module

module/export

module/named

procedure

thread_local