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

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Modules : Global Variables in Modules

Global Variables in Modules

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

global glo1, glo2, ...

Parameters

glo1, glo2, ...

-

one or more (optionally initialized) global variable names

Description

• 

A module definition may contain a declaration of one or more global variables. These are exactly analogous to global variables of procedures. Each expression glo1, glo2, ... must be a symbol.

• 

Changes (by assignment) to the value of a global variable made anywhere within a module definition are visible at global scope, once the code effecting the change executes.

  

Note: The body of a module definition executes when the module definition is evaluated (during instantiation), while the bodies of (exported) procedures execute when they are called.

• 

Declaring a variable to be global in a module prevents the implicit scoping rules from causing it to be declared local implicitly. Even if implicit scoping rules do not force a variable to be declared local implicitly, you must always declare all of your global variables.

Examples

m := module()
    global    `convert/pair`, `print/PAIR_`;
    export    cons, car, cdr;
    `convert/pair` := proc( expr )
        if type( expr, [ 'anything', 'anything' ] ) then
            cons( op( expr ) )
        else
            error "cannot convert %1 to a pair data structure", expr
        end if
    end proc:
    `print/PAIR_` := proc()
        local ``;
        ``( args )
    end proc:
    cons := (a,b) -> 'PAIR_'( a, b );
    car := curry( op, 1 );
    cdr := curry( op, 2 );
end module:

convertu,v,pair

u,v

(1)

m:-cdr

v

(2)

See Also

module

module/export

module/local

procedure