Modula-2 Extensions For Experts

Syntax Reference For Advanced Programmers

Procedure types & variables

TYPE                         suffix Pr
     DoSomethingPr = PROCEDURE (CARDINAL, VAR INTEGER): BOOLEAN;

  Use: procedure variables

Pointers

Libraries

= export constants, types, procedures and variables to other modules.

The Definition Module

DEFINITION MODULE DemoLibrary;

  CONST
    STRING_MAX = 81;

  TYPE
    StringTp = ARRAY[0..STRING_MAX] OF CHAR;

  PROCEDURE StringLength(str: StringTp): CARDINAL;
                                 procedure heading only
                                 only open arrays or array types
  VAR
    errorMessage: StringTp;

END DemoLibrary.

The Implementation Module

IMPLEMENTATION MODULE DemoLibrary;

  PROCEDURE StringLength(str: StringTp): CARDINAL;
      ...
    BEGIN
      ...                          procedure implementation
  END StringLength;

BEGIN
  errorMessage := "no error until now";  initialisation of variables

END DemoLibrary.

Use

MODULE TestLibrary;

  FROM IO IMPORT WrStr, WrLn;     import procedures
  IMPORT DemoLibrary;            or import the whole module

  VAR
    str1: DemoLibrary.StringTp;   use

BEGIN
  WrStr(DemoLibrary.errorMessage);

END;

Use within XDS

    or

Compile options

Further (see Modula-2 book)