Global Variables in Modules - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Modules : module/global

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

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam