Computer Languages A to Z: Modula 2
by Gary L. Ratliff, Sr. (eronstuc)
Introduction to Modula 2
Modual2 was invented by Niklaus Wirth, who was the inventor of the language Pascal. In addition to this language, he also invented Oberon2, which is an object orientated version of Modula2. Once Pascal was introduced to the computing world, it was readily adapted as a teaching language. Soon, there were many variations on the language which Wirth took to indicate short comings in the language. This prompted him to develop a language named Modula in 1975, and from this, to later develop Modula 2 in 1979.
The most distinguishing feature of Modula 2 is that programs may be developed and compiled in separate modules. The language was introduced with a set of features of the language, and also a set of modules which were not regarded as parts of the language, but which were regarded as desirable by Wirth to use the language.
As with Pascal, soon various implementations were developing their own sets of these modules. This action led to an effort to standardize the language and make certain modules have required names and items in the procedures supported by the module. This results in a programming style which allows the features with either the Wirth named modules or the names as required by the ISO standard.
Learning the Modula 2 Language
We now need to locate a tutorial which will introduce us to the Modula 2 language. The easiest method is to enter the words Modula 2 into the Google search engine. From the items shown, select the item Modula Home, and you will receive the following page:
Here we find that a tutorial for novice users is most likely to be one which we may use to learn the features of the language. As this tutorial also assumes that the reader is new to computers, it serves as an introduction to the entire field. To reach it, just click of the line in the above page named "Modula-2 Tutorial," and this will bring up the following page:
First, the best approach would be to just start with the preface and introduction. This will let you know that Part I of the tutorial is required reading before you begin to peruse either Part II or Part III. On reading this tutorial, you learn that some of the most important information only has the text: "Under development." That first appears in the section named Input/Output.
Second, it is for this reason that I suggest that you also use the tutorial by Rick Sutcliffe. This tutorial is very complete. It also offers many complete programming examples. To find this tutorial, you will click the LINKS item in the above page. This will produce the following page:
Once on this page, you will reach the tutorial by clicking the item: "Modula 2: Abstractions for Data and Programming Structure." This will produce the following page:
This is a text book in 19 chapters. Each of the chapters will have several sections, which will be navigated by clicking the link to each section which will be found in the upper right portion of the page.
Note that each chapter will have a quiz, and that answers to the material are provided. With these two tutorials, one should have little problems in learning to use the Modula 2 language.
A Compiler for Modula 2
It is in the selection of a compiler that one experiences some problems. At first, the GNU Modula 2 reported that it was not finished. However, recent checks have reported that the system was now complete. Yet, following the directions for installing the system both on the PCLinuxOS partition, and on one I have for Debian Lenny 5.0, yielded unsuccessful results. Here are the instructions given for obtaining and installing the system:
For example you should be able to download the latest version of GNU Modula-2 and GCC using these commands:
wget http://flopssie.comp.glam.ac.uk/download/c/gcc-4.1.2+gm2.\ cvs-latest.tar.gz tar zxf gcc-4.1.2+gm2-cvs-latest.tar.gzThis step is successful and will get the latest version of these two files. Next, it becomes necessary to build the system. So the text continues:
"On a GNU/Linux system, you should also be able to build it using these commands. The following commands assume your shell is '/bin/bash'. To build GNU Modula-2 type:"
mkdir -p $HOME/opt mkdir -p build-4.1.2 cd build-4.1.2 ../gcc-4.1.2+gm2-cvs-latest/configure –-enable-languages=c,c++,gm2 \ --disable-multilib –enable-checking=all –prefix=$HOME/opt make "SHELL=/bin/bash"To install GNU Modula-2, after a successful build, type:
make "SHELL=/bin/bash" install cd ..Now you should be able to perform:
export PATH=$HOME/opt/bin:$PATH cd gcc-4.1.2/gcc/gm2/examples/hello makewhich will create an 'a.out' for the infamous hello world example.
However, when attempting the 'make "SHELL=/bin/bash"' the system reports "/lib/cpp fails sanity check". By tracing the links for cpp in its trail beginning with "/lib/cpp", we learned that this refers to the gcc version 4.4, and not the version 4.1.2 as should be used by this system. Now, as the article on Fortran just appeared and this article should not reach print until August 2010, perhaps by this time an easy to install version of the GNU Modula-2 system will be in the repository. The complete system has just been finished and they are setting up deb packages for Lenny with, I would assume, others to follow.
Another system is the XDS, which provides translation from a mod file into ansi standard C. Simply download either the native language packet or the C packet and install it. Then, one sets the path to include its location. The command xm hello.mod yields a file hello.c. Yet when attempting to compile this with gcc, it reports that the inout.h, and several other files, can't be located. The xds package does double duty in being able to compile Oberon2, which is the OO version of Modula-2, also developed by Niklaus Wirth.