Global Variables in Modules - Maple Help

Online Help

All Products    Maple    MapleSim

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

Global Variables in Modules

Calling Sequence

global glo1, glo2, ...


glo1, glo2, ...


one or more (optionally initialized) global variable names



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.


m := module()
    global    `convert/pair`, `print/PAIR_`;
    export    cons, car, cdr;
    `convert/pair` := proc( expr )
        if type( expr, [ 'anything', 'anything' ] ) then
            cons( op( expr ) )
            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:







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