Pascal – Modules and Restricted Types

Spread the love

Pascal has been a great application, which has been used for a long time for different purposes. There is a big list of software testing companies in bangalore which use this application. There are a wide range of options and features available in pascal with the help of modules and restricted types. It is highly recommended for people to know and understand different kinds of options available in the application and the software because it plays a vital role in determining the objective of the process in an easy way.

Restricted Types of Pascal

Restricted types provide a means of hiding the details of a type when it is exported. The originator of a module may declare a “restricted” version of a type, and export only the restricted form. An importer can declare variables of such a type, and pass them as parameters to procedures imported from the originating module, but can only treat them as black boxes with no knowledge of their internal structure. Within the module, the restricted parameters are of the unrestricted original type.

Modules of Pascal

Modular construction is normally appropriate to larger programs, and small examples inevitably appear trivial. However, the three related modules which follow demonstrate a number of the possibilities.

Module one exports an interface named i1, containing two constants named lower and upper. A variable dummy is declared but not exported. Module one has a minimal module block.


EXPORT i1 = (lower,upper);

CONST  lower = 0;

       upper = 11;   {must be prime}

VAR    dummy: Boolean;

END {of module-heading};

END {of module-block}.

Module two imports the constants lower and upper from one, uses them to define a type, and also re-exports them. It exports two interfaces named i2 and j2. Interface i2 contains the type subr; j2 contains the constants lower and upper. Module two also has a minimal module block.


EXPORT i2 = (subr); {has just one constituent}

       j2 = (lower,upper);

IMPORT i1;     {import all (both) constituents}

TYPE   subr = lower..upper;

END {of module-heading};

END {of module-block}.

Module three demonstrates qualified import and renaming. It exports one interface i3 containing a function, a type, and two constants. It imports interfaces i1 and i2 qualified, so references to the constituents within the module are prefixed with the interface-names; further, the type subr is renamed lim_range on import, so it is referred to as i2.lim_range. The constants lower and upper are renamed on export as lim_lower and lim_upper. The function-heading of limited is declared in the module-heading, and the function-definition in the module-block. Note that the parameter-list and result-type of limited are not repeated in the definition; this arrangement is similar to forward-declared procedures in classic Pascal.

MODULE three;

EXPORT i3 = (limited,i2.lim_range, {function and type}


IMPORT i1 QUALIFIED;  {lower, upper to be referenced 

                       as i1.lower and i1.upper}

       i2 QUALIFIED ONLY (subr=>lim_range);

FUNCTION limited(x: integer): i2.lim_range;

END {of module-heading};

FUNCTION limited;


    IF x < i1.lower THEN limited := i1.lower


      IF x > i1.upper THEN limited := i1.upper

      ELSE limited := x

  END {limited};

END {of module-block}.

Leave a Reply

Your email address will not be published. Required fields are marked *