the export declaration - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Modules : Module Exports : module/export

`export` - the export declaration

Calling Sequence

export e1, e2, ...

Parameters

e1, e2, ...

-

one or more (optionally typed and/or initialized) names to be exported

Description

• 

The export clause in a module definition is used to "declare" one or more names that are to be made available to clients of the module once the module has been instantiated. The names are accessible outside the module definition by using the member selection operator :-. These names are called the "exports" of the module. Each of the expressions e1, e2, ... must be either a symbol, or an expression of the form symbol::type. An export declared as symbol::type effects a type assertion on the assigned value of the export.  If kerneloptsassertlevel is set to 2, assigning a value that does not match the declared type raises an exception.

• 

The essential feature of the exports of a module is that they are local to the module; that is, they are not global names. The scope of an exported name is exactly the same as that of a local variable of the module. The primary difference is that an exported name is not private to the module. It is accessible even outside the definition of the module.

• 

Exported names are unique to the execution of the module definition in which they are bound. A fresh set of exported names is created each time a module definition is executed (which is part of its evaluation).

• 

Within the module, the evaluation rules for module exports are identical to those for module locals and to those for local variables in procedures. Outside of the module, exported names have the same evaluation rules as global variables. (See eval for details.)

• 

The set of names exported by a module is fixed and is set at the time the module definition is evaluated. You cannot modify the set of exports of an instantiated module.

• 

Names must be explicitly declared to be exported. A name cannot be resolved as an export by implicit scoping rules.

• 

A module m may export a name s which is assigned a module, within the body of m. (In other words, s is a submodule of m.) The exports of the submodule s are accessible by first selecting the submodule s of m using m:s, and then selecting an appropriate exported member e of s by m:s:ⅇ.

Examples

Declare some exported names.

P:=moduleoptionpackage;exporta,b,c;end module

P:=moduleoptionpackage;exporta,b,c;end module

(1)

Now access them with the : operator.

P:-a

a

(2)

evalba=P:-a

false

(3)

unprotectP:-a;P:-a:=5

a:=5

(4)

P:-a

5

(5)

a

a

(6)

withP

a,b,c

(7)

a

5

(8)

The visibility of exports is, in some sense, "transitive".

m := module()
    export s, p;
    s := module()
        export e;
        e := 2
    end module;
    p := proc()
        s:-e
    end proc
end module:

m:-s:-e

2

(9)

m:-p

2

(10)

If either s is not exported from m, or e is not exported from s, then this does not work.

m := module()
    export p;
    local s;
    s := module()
        export e;
        e := 2
    end module;
    p := proc()
        s:-e
    end proc
end module:

m:-s:-e

Error, module does not export `s`

m:-p

2

(11)

Here, e is not even available inside the body of m.

m := module()
    export p;
    local s;
    s := module()
        local e;
        e := 2
    end module;
    p := proc()
        s:-e # error, not an export of s
    end proc
end module:

m:-s:-e

Error, module does not export `s`

m:-p

Error, (in p) module does not export `e`

See Also

kernelopts, local, module, module/package


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