Skip to main content
Top

1986 | Book

A Guide to Modula-2

Author: Kaare Christian

Publisher: Springer New York

Book Series : Monographs in Computer Science

insite
SEARCH

About this book

Modula-2 is a simple yet powerful programming language that is suitable for a wide variety of applications. It is based on Pascal, a successful programming language that was introduced in 1970 by Niklaus Wirth. During the 1970's Pascal became the most widely taught programming language and it gained acceptance in science and industry. In 1980 Dr. Wirth released the Modula-2 program­ ming language. Modula-2 is an evolution of Pascal. It improves on the successes of Pascal while adding the MODULE - a tool for ex­ pressing the relations between the major parts of programs. In ad­ dition Modula-2 contains low-level features for systems program­ ming and coroutines for concurrent programming. Programming languages are important because they are used to express ideas. Some programming languages are so limited that certain ideas can't be easily expressed. For example languages that lac k floating point arithmetic are inappropriate for scientific com­ putations. Languages such as Basic and Fortran that lack recur­ sion are unsuitable for text processing or systems programming. Sometimes a programming language is useable for a certain appli­ cation but it is far from ideal. A good example is the difficulty of writing large programs in pure Pascal. Pascal is a poor language for large jobs because it lacks facilities for partitioning a program viii Preface 6< ; ~~~~er 0\ Sheet Metal Tube /" 0 (to Affix Eraser to Shaft) ~ Hollow Wooden Shaft A Lead Core Figure 1. An exploded diagram. into separate pieces that can be developed independently.

Table of Contents

Frontmatter

Moving to Modula-2

Frontmatter
Chapter 1. Modula-2 and Pascal
Abstract
Modula-2 was introduced in 1980 by its author Niklaus Wirth. Wirth is a well known computer scientist as a result of the widespread acceptance of his earlier programming language, Pascal. Modula-2, like Pascal, is a small, simple, consistent language. Modula-2 is an improvement of Pascal. It is an excellent learning language and it is also an excellent language for large, commercial and scientific applications.
Kaare Christian
Chapter 2. Data in Modula-2
Abstract
Let’s define data as information that is stored and manipulated by a computer. Manipulation of data is performed by programs — that’s where Modula-2 comes in. Within a Modula-2 program there are two different forms of data: constants and variables.
Kaare Christian
Chapter 3. Control Flow in Modula-2
Abstract
Unless instructed otherwise, a computer will process the operations in a program in order, one after another. However most programming tasks have repetitive elements, and most involve alternatives. Repetitive elements are managed by instructing the computer to return to a earlier point in the program. Alternatives are managed by directing the computer to go to one of several places in a program. In either case the programmer is controlling the flow of execution of the program.
Kaare Christian
Chapter 4. Procedures
Abstract
Your first hurdle in learning to program is getting your first small program to work correctly. As you become more skilled your programs will naturally become larger and more sophisticated. For a large program, managing complexity means dividing a large problem into smaller, more understandable units.
Kaare Christian
Chapter 5. Arrays
Abstract
A data structure is a way to package data, so that data can be bound together into a single unit. The hallmark of a structured TYPE is the idea of components (elements). Data TYPES that lack components are called simple TYPES because each variable contains a single value.
Kaare Christian

Modules

Frontmatter
Chapter 6. Local MODULES
Abstract
A local MODULE is a MODULE that is nested within another. (Occasionally a local MODULE is nested within a PROCEDURE.) Improving the organization of a program is the most common reason for using a local MODULE. They are also used to protect critical regions of code (Section 17.2) and to provide for static variables (Appendix VII). Placing several related PROCEDURES and data structures into a local MODULE binds them together and segregates them from the outer MODULE.
Kaare Christian
Chapter 7. Definition Modules
Abstract
The major feature that distinguishes Modula-2 from Pascal is the MODULE. The assumption that underlies Pascal is that many useful programs can be written on a few pages. This is sufficient for student projects or simple programs. One new idea of Modula-2 is that many programs are so complicated that they must be divided into smaller pieces so that they can be understood. Thus Modula-2 works wherever Pascal does, but it also is an ideal language for larger projects.
Kaare Christian
Chapter 8. Implementation Modules
Abstract
An IMPLEMENTATION MODULE is the hidden part of a global MODULE. It is where the services of a global MODULE are actually performed, unlike the DEFINITION MODULE, which publicizes those services. The heading of an IMPLEMENTATION MODULE starts with the word IMPLEMENTATION. Otherwise an IMPLEMENTATION MODULE is constructed like a program MODULE.
Kaare Christian
Chapter 9. Common Global MODULES
Abstract
Every implementation of Modula-2 includes a set of global MODULES to round out Modula-2’s capabilities. There are no absolute standards for these global MODULES, instead there are suggestions detailing the facilities that should be provided. You should expect minor differences in these MODULES from one system to another.
Kaare Christian
Chapter 10. Desk Calculator with Variables and Assignments
Abstract
The goal of this final chapter in Part III is to learn to partition a large problem into several pieces so that it is easier to manage. Certain things can be proven in computer science, but I doubt that it is possible to prove that a certain program organization is optimal. If you have some programming experience, you may be able to look at a particular program organization and evaluate its merits. Those of us who have tried writing non-trivial program can attest to the difficulty of organizing a large software project. One difficult chore is choosing an organization strategy. Although there are no “laws,” there are several factors that should be considered.
Kaare Christian

Advanced Data Types

Frontmatter
Chapter 11. Enumerations
Abstract
An enumeration is simply a list. Let me enumerate some advantages of Modula-2. Modula-2 is a coherent, powerful, elegant, modular, structured programming language.
Kaare Christian
Chapter 12. Sets
Abstract
A mathematical SET is a collection of objects. For example consider the primary colors Red, Green, and Blue. We can form eight distinct SETS from these three objects, ranging from the null SET (zero members) to the full SET with three members.
Kaare Christian
Chapter 13. Records
Abstract
Situations often arise in programming where it helps to take two points of view towards a set of variables. For example the variables describing the characteristics of a sailboat might include the BoatManufacturer, the LengthOverAll, the LengthAtWater-Line, the SailArea, and the MaximumCrewSize. On the one hand we like to think about the individual variables and their values, for example we might like to assign the value 8 to the variable MaximumCrewSize. On the other hand it is often convenient to think of these variables as a single entity. We might want to pass this entire description of a sailboat to a PROCEDURE, or we might want to assign the values of one sailboat variable to another.
Kaare Christian
Chapter 14. Dynamic Data
Abstract
In many programs it is possible to decide, as the program is being designed, how many variables of each TYPE are needed. In these programs each variable is given a name at the outset and it can be referred to as needed using its name. Named variables are the rule in Modula-2 and many programmers never need Modula-2’s dynamic (anonymous) data facilities.
Kaare Christian
Chapter 15. Procedure Variables
Abstract
In the previous chapter we introduced the idea of a POINTER variable that could be used to access some other variable. In this chapter we introduce a similar idea — the concept of a procedure variable that can be used to invoke a PROCEDURE.
Kaare Christian

Systems Programming

Frontmatter
Chapter 16. TYPE Relaxation
Abstract
There are two purposes for having a given TYPE for every variable. First the TYPE of a variable indicates what operations apply to that variable. This makes variables more expressive. In addition the TYPE of a variable imposes certain restrictions on that variable. Variables can only be used with compatible variables. This makes programs more robust and it eliminates numerous common errors.
Kaare Christian
Chapter 17. Programming Hardware
Abstract
One aspect of systems programming is writing programs that actually control the computer hardware. Every computer contains peripheral devices to transfer data between the computer and the outside world. For example most computers are connected to terminals so that people can interact with the computer. Most computers capable of running Modula-2 are also connected to disks so that information can be stored for long periods of time. Most computers are connected to printers, and most larger computers have clocks so that they can keep track of time. Even simple computers, such as a computer controlling a microwave oven, has a small collection of switches and sensors used for input and a few actuators used for output.
Kaare Christian
Chapter 18. Coroutines
Abstract
Coroutines are built into Modula-2 so that it may be used to write interrupt handlers, runtime systems, event driven programs, and even complete operating systems. Coroutines are a primitive concept. They allow programmers to manage situations where several things are (or appear to be, or are best thought of as) happening simultaneously.
Kaare Christian
Chapter 19. Device Drivers
Abstract
One important feature of Modula-2 is the ability to write coroutines that serve as device drivers (also called interrupt handlers) for interrupting devices. This ability considerably enhances Modula-2’s suitability for systems programming, and it means that many systems can be written entirely in Modula-2 without resorting to lower level languages.
Kaare Christian
Backmatter
Metadata
Title
A Guide to Modula-2
Author
Kaare Christian
Copyright Year
1986
Publisher
Springer New York
Electronic ISBN
978-1-4612-4892-7
Print ISBN
978-1-4612-9349-1
DOI
https://doi.org/10.1007/978-1-4612-4892-7