home *** CD-ROM | disk | FTP | other *** search
- Introduction to the Modula-2 Tutorial
-
-
- Welcome to the programming language Modula-2, a very
- complete, high level language with many advanced features.
- Modula-2 was designed by Niklaus Wirth, the designer of
- Pascal. Based on experience with Pascal, Modula-2 was
- designed to make up for many of the deficiencies noted by
- programmers worldwide, and the changes make it a very
- powerful language with few limitations. In spite of its
- power, Modula-2 retains the simplicity of Pascal and can be
- used for small applications as easy as Pascal could be used.
-
- MODULA-2 TUTORIAL - PART I
-
- Even though there are many similarities between the two
- languages, the differences are significant. This tutorial
- was written considering both the similarities and the
- differences between the languages. The first part of this
- tutorial is composed of those features that are common to
- Pascal and Modula-2 and are also of a fundamental nature.
- You will need to study all of Part I in order to write
- meaningful Modula-2 programs. If you are already a fairly
- experienced Pascal programmer, you will absorb this material
- very fast. Be sure to go through it all at least once
- because there are many small differences between the
- languages that you must consider.
-
- MODULA-2 TUTORIAL - PART II
-
- The topics taught in Part II of this tutorial are those
- advanced features that are also available in Pascal. Some of
- these topics are pointers, dynamic allocation, records, and
- linked lists. They are very powerful tools that can be used
- to great advantage but are quite often overlooked by many
- Pascal programmers that I have talked to. These are the
- tools that give Pascal and Modula-2 an advantage in
- flexibility over such languages as BASIC and FORTRAN. They
- do require a bit of deep concentration to understand, but
- you will be greatly rewarded if you take the time to
- understand and use them.
-
- MODULA-2 TUTORIAL - PART III
-
- Part III of this tutorial covers those aspects of
- Modula-2 that are not included in Pascal in any way. Some of
- the topics are independent compilation, the entire topic of
- modules, and concurrent processing. These are advanced
- topics and some of these topics may be the reasons that you
- selected Modula-2 as a programming language. The material
- covered in Part I in conjunction with that covered in Part
- III can lead to some very powerful programming techniques.
-
-
-
-
- Page 1
-
-
-
-
-
-
-
-
-
- Introduction to the Modula-2 Tutorial
-
-
- To efficiently use this tutorial, you must carefully
- study all of the material in Part I, then you can do a lot
- of jumping around in Parts II and III and still cover the
- material in a meaningful manner. You may also choose to
- only study some chapters of the last two parts in order to
- learn the needed material for the programming problem at
- hand. I would like to emphasize that it is important that
- you cover the material in Part I very carefully and in order
- since so much depends on what was taught before. When you
- get to the last two parts, comments at the beginning of each
- chapter will tell you what parts need to be reviewed in
- order to effectively use the material in the chapter.
-
- FOR THE BEGINNING PROGRAMMER
-
- If you are a novice to computer programming, this
- course is for you because it is assumed that you know
- nothing about programming. Many sections, especially in the
- early chapters, will cover very basic topics for your
- benefit. The biggest problem you will have will be setting
- up your compiler for use, since this can be a very difficult
- task. Possibly you know someone with experience that would
- be willing to help you get started.
-
- FOR ALL PROGRAMMERS
-
- There are, at this time, a very limited number of
- Modula-2 compilers available, but it would not be possible
- to include notes on every compiler about how to install it
- for your computer. The COMPILER.DOC file on your
- distribution disk contains notes on all of the compilers we
- have had access to and some of the difficulties in setting
- them up for the IBM-PC or near compatibles. In addition,
- all compilers do not implement all functions defined in
- Niklaus Wirth's definition of the language. As many of
- these as we have found are listed in the same file.
- Finally, all of the problems in compiling the files on this
- disk are noted in the COMPILER.DOC file. It would be worth
- your effort to print out this file and keep the hardcopy
- handy while you are working your way through the lessons.
-
- Modula-2, as defined by Niklaus Wirth, contains no
- provisions for input or output because they are so hardware
- dependent. It is up to each compiler writer to provide you
- with supplemental procedures for handling I/O (input/output)
- and a few other machine dependent features. Niklaus Wirth
- did recommend a library of I/O routines that should be
- available and most compilers contain at least those
- facilities, and usually provide many more. The COMPILER.DOC
- file will contain notes about differences in these
- facilities for those compilers which we have access to. The
-
-
- Page 2
-
-
-
-
-
-
-
-
-
- Introduction to the Modula-2 Tutorial
-
-
- COMPILER.DOC file will be updated anytime new information is
- available.
-
- SIMPLE EXAMPLES WILL BE USED
-
- All of the instructional programs are purposely kept
- simple and small to illustrate the point intended. It is of
- little value to you to present you with a large complex
- program to illustrate what can be illustrated in a small
- program better. In addition, every program is complete, and
- can be compiled and run. Program fragments frequently pose
- as many questions as they answer.
-
- Because it would be a disservice to you to teach you a
- lot of simple techniques and never show you how they go
- together in a significant program, chapters 9 and 16 contain
- several larger example programs. A relatively small amount
- of description is given about these programs because you
- will have already covered the details and only need a quick
- overview of how to put the various constructs together. You
- will find some of these programs useful and will have the
- ability to modify and enhance them for your use since you
- have the source code.
-
- SOME VARIABLE NAMES SEEM SILLY, WHY IS THAT?
-
- I have seen example programs with the same name
- everywhere, and had a hard time deciding what names were
- required and what could be changed to something more
- meaningful. For example a "SORT" program is in a file named
- "SORT", the program name is "SORT", the input file is named
- "SORT", and variables were named "SORT1", SORT2", etc. This
- was no help to myself, a novice sorter, and would be no help
- to you. For that reason the first program is in a file
- named "PUPPYDOG.MOD" and the module name is "PuppyDog". It
- should be obvious to even the newest programmer that the
- name of a module can be anything if it is allowed to be
- "PuppyDog". You will learn later that well selected names
- can be a great aid in understanding a program. This will be
- evident in some of the early programs when variable names
- are chosen to indicate what type of variable they are.
-
- Some compilers require that the module name be the same
- as the file name, and all require them to agree when you get
- to global modules because of the way "Type checking" is
- accomplished. It would be best for you to get into the
- habit of naming them both the same now. For that reason,
- all of the example programs use the same name for the file
- name and for the module name. Your compiler may allow you
- to use different names. It will be left up to you to study
- your manual and see if this is so for your compiler.
-
-
- Page 3
-
-
-
-
-
-
-
-
-
- Introduction to the Modula-2 Tutorial
-
-
-
- WHAT IS A COMPILER?
-
- There are two primary methods used in running any
- computer program that is written in a readable form of
- English. The first method is an interpreter. An
- interpreter is a program that looks at each line of the
- "english" program, decides what the "english" on that line
- means, and does what it says to do. If one of the lines is
- executed repeatedly, it must be scanned and analyzed each
- time, greatly slowing down the solution of the problem at
- hand.
-
- A compiler on the other hand, is a program that looks
- at each statement one time and converts it into a code that
- the computer understands directly. When the compiled
- program is actually run, the computer does not have to
- figure out what each statement means, it is already in a
- form the computer can run directly, hence a much faster
- execution of the program. Due to the nature of Modula-2,
- there will be few, if any, interpreters.
-
- WHAT ABOUT THE PROGRAMMING EXERCISES?
-
- The programming exercises at the end of each chapter
- are a very important part of the tutorial. If you do them,
- you will embed the principles taught in each chapter more
- firmly in your mind than if you ignore them. If you choose
- to ignore them, you will be somewhat adept at reading
- Modula-2 programs but very ineffectual at writing them. By
- doing the exercises, you will also gain considerable
- experience in using your editor and compiler.
-
- It will be assumed that you know how to use your
- compiler and that you have some kind of an editor for use
- with the example files. With the above in mind, you are now
- ready to begin your tour of Modula-2.
-
- A sample program is included in this chapter for you to
- try with your compiler. It is left as an exercise for you
- to compile and run FIRSTEX.MOD. When you can successfully
- compile and run this program, you are ready to begin the
- tutorial on Modula-2 programming. Do not worry about what
- the statements mean in FIRSTEX.MOD, you will have a complete
- understanding of this program by the time you complete
- chapter 4.
-
-
-
-
-
-
-
- Page 4
-
-