# Modules

A module has the form:

        MODULE id EXPORTS Interfaces;
          Imports;
        Block id.

where `id` is an identifier that names the module, `Interfaces` is a list of distinct names of interfaces exported by the module, `Imports` is a list of import statements, and `Block` is a block, the body of the module. The name `id` must be repeated after the `END` that terminates the body. "`EXPORTS Interfaces`" can be omitted, in which case `Interfaces` defaults to `id`.

If module `M` exports interface `I`, then all declared names in `I` are visible without qualification in `M`. Any procedure declared in `I` can be redeclared in `M`, with a body. The signature in `M` must be covered by the signature in `I`. To determine the interpretation of keyword bindings and parameter defaults in calls to the procedure, the signature in `M` is used within `M`; the signature in `I` is used everywhere else.

Except for the redeclaration of exported procedures, the names declared at the top level of `Block`, the visible imported names, and the names declared in the exported interfaces must be distinct.

For example, the following is illegal, since two names in exported interfaces coincide:

        INTERFACE I;
          PROCEDURE X();  ...

        INTERFACE J;
          PROCEDURE X();  ...

        MODULE M EXPORTS I, J;
          PROCEDURE X() = ...;

The following is also illegal, since the visible imported name `X` coincides with the top-level name `X`:

        INTERFACE I;
          PROCEDURE X();  ...

        MODULE M EXPORTS I;
          FROM I IMPORT X;
          PROCEDURE X() = ...;

But the following is legal, although peculiar:

        INTERFACE I;
          PROCEDURE X(...);  ...

        MODULE M EXPORTS I;
          IMPORT I;
          PROCEDURE X(...) = ...;

since the only visible imported name is `I`, and the coincidence between `X` as a top-level name and `X` as a name in an exported interface is allowed, assuming the interface signature covers the module signature. Within `M`, the interface declaration determines the signature of `I.X` and the module declaration determines the signature of `X`.

    Last modified on Wed Apr  3 09:39:03 PST 1996 by heydon
         modified on Mon Apr 18 14:04:34 PDT 1994 by kalsow