Writing modules (The GNU Algol 68 Compiler)

#### 2.2.1 Writing modules ¶

A definition module is a construct that provides access to a set of publicized definitions. They appear in the outer reach of a prelude packet and constitute its only contents (see Packets). They are composed of a prelude and a postlude. The publicized definitions appear in the module’s prelude.

Consider for example the following definition module, which implements a very simple logging facility:

    module Logger =
    def int fd = stderr;
        pub string originator;
        pub proc log = (string msg) void:
               fputs (fd, (originator /= "" | ": ") + msg + "'n");

        log ("beginning of log'n")
    postlude
        log ("end of log'n")
    fed

The module text delimited by `def` and `fed` gets ascribed to the module indicator `Logger`. Module indicators are bold tags.

The prelude of the module spans from `def` to either `postlude`, or to `fed` in case of modules not featuring a postlude. It consists of a restricted serial clause in a void strong context, which can contain units and declarations, but no labels or completers. The declarations in the prelude may be either publicized or no publicized. As we shall see, publicized indicators are accessible within the reach of the defining module publicizing them. Publicized declarations are marked by preceding them with `pub`.

In our example the module prelude consists of three declarations and one unit. The tag `fd` is not publicized and is to be used internally by the module. The indicators `originator` and `log`, on the other hand, are publicized and conform the interface of the module. Note how the range of the prelude also covers the postlude: the `log` procedure is reachable there, as it would be `fd` as well.

The postlude of the module is optional and spans from `postlude` to `fed`. It consists of a serial clause in a `void` strong context, where definitions, labels and module accesses are not allowed, just units.