export function definition | function predefinition | global variable declaration | global variable predefinition | constant declaration | constant predefinition | catch declaration | (as opaque)? record declaration | (as opaque)? record predeclaration OR import module name export? prefix declararion (export? use declaration)*
You can export various properties of a module using the
export keyword. Normally, the properties of a module are private to the module. In order to make properties available for use in the program that imports the module, you must explicitly export those properties. The properties that are available for export from a module are as follows:
To export a function from a module, replace the word
define with the word
export string source function timestamp as output date "=xY-=M-=D =H:=m:=s"
You can export a function predefinition (using
elsewhere) but if you do so, you must also export the function definition. It is an error if the export status of the predefinition and the definition do not match.
To export a global variable from a module, precede the word
global with the word
You can export a global predefinition (using
elsewhere) but if you do so, you must also export the global definition. It is an error if the export status of the predefinition and the definition do not match.
To export a constant from a module, precede the word
constant with the word
You can export a constant predefinition (using
elsewhere) but if you do so, you must also export the constant definition. It is an error if the export status of the predefinition and the definition do not match.
To export a catch label from a module, replace the word
declare with the word
export catch close-parenthesis
You will need to export catch names from a module if there is any chance of having a catch and a throw of the same name on opposite sides of the module boundary (that is, one inside the module, and one outside it).
To export a record type declaration from a module, replace the word
declare with the word
As with functions, you can export a record type pre-declaration:
As with functions, you must also export the record type declaration. The export status of the declaration and the pre-declaration must match.
Note that exporting a record type declaration makes it possible to declare variables of that type in the importing program or module, but it does not create or export a record of the declared type.
You can also export an opaque record type declaration by following the word
export with the word
as opaque. If a record type declaration is exported as opaque, the importing program or module will not have access to the fields of record variables of that type. They will be able to create and manage variables of this type, but will not be able to access or manipulate their contents. Only code within your module will be able to address and access the fields of the records. This allows you to use a module to hide data and restrict operations on the data to thse supported by the exported functions.
You can export some or all of the properties of a module that you have imported into your module. For instance, suppose that you created a module that exports a record type that uses floating point numbers for fields. The module will need to import the OMFLOAT library to allow fields of type float to be defined.
However, if a program that imports this module wants to access the fields of point records, it will also need access to the float data type and the operators that the OMFLOAT library provides for working with floating point numbers. Rather than requiring users of your module to import the OMFLOAT library separately, you can re-export its exported properties by including the word
export before the prefix declaration:
module shared as point.xmd import "omfloat.xmd" export unprefixed export record point field float x field float y
You can also re-export individual imported properties, or exclude them from being reexported by combining
export with a
Notice that if you re-exported the properties of a module that you had imported with a prefix, that prefix is also exported, so that if your module was defined as follows:
module shared as point.xmd import "omfloat.xmd" export prefixed by fp. export record point field float x field float y
The importing program would have to use that prefix on the names of the float library properties, in addition to any prefix declared for your module: