Pascal – Modules and Restricted Types

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.

MODULE one;

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.

MODULE Two;

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}

             i1.lower=>lim_lower,i1.upper=>lim_upper);

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;

  BEGIN

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

    ELSE

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

      ELSE limited := x

  END {limited};

END {of module-block}.

Recent Posts

How Much Do Website Developers for Small Business Charge

How Much Do Website Developers for Small Business Charge

A website that generates actual clients is what many small business owners desire. However, most people have trouble answering one crucial question. Before beginning the project, they want to know how much small company website developers charge and what to prepare...

How to Build a Website for My Business That Attracts Local Customers

How to Build a Website for My Business That Attracts Local Customers

Establishing an online presence is now required in the current digital era. No matter how big or small, a website is essential for reaching clients, showcasing goods and services, and establishing trust. Knowing how to create a website that draws in local clients and...

How to Find the Best Website Designers for Small Business

How to Find the Best Website Designers for Small Business

A professional website is essential for any small business in today's digital world. For many prospective clients, your website serves as their initial point of contact. It helps you reach a larger audience, establishes trust, and represents your brand. However,...

Start an Online Passive Income Business With Minimal Investment

Start an Online Passive Income Business With Minimal Investment

Starting an online business that earns money passively has become one of the most reliable ways to build financial security. Many people want to escape the pressure of long working hours. Others want to create an extra stream of income without taking a big risk. The...

Affordable Business Ideas to Make Money While Working Part Time

Affordable Business Ideas to Make Money While Working Part Time

More people today dream of earning extra income without leaving their current job. Some want to support their family. Some want more financial freedom. Others want to explore a passion that they cannot pursue full-time yet. Thanks to the internet and changing work...