home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / MODULA / MODTUTOR / INTRO.TXT < prev    next >
Text File  |  1993-12-01  |  12KB  |  257 lines

  1.                     Introduction to the Modula-2 Tutorial
  2.  
  3.  
  4.              Welcome  to the programming language Modula-2,  a  very
  5.         complete,  high  level language with many advanced features.
  6.         Modula-2  was  designed by Niklaus Wirth,  the  designer  of
  7.         Pascal.   Based  on  experience with  Pascal,  Modula-2  was
  8.         designed  to make up for many of the deficiencies  noted  by
  9.         programmers  worldwide,  and  the  changes make  it  a  very
  10.         powerful  language  with few limitations.   In spite of  its
  11.         power,  Modula-2 retains the simplicity of Pascal and can be
  12.         used for small applications as easy as Pascal could be used.
  13.  
  14.                          MODULA-2 TUTORIAL - PART I
  15.  
  16.              Even though there are many similarities between the two
  17.         languages,  the differences are significant.   This tutorial
  18.         was  written  considering  both  the  similarities  and  the
  19.         differences  between the languages.   The first part of this
  20.         tutorial  is composed of those features that are  common  to
  21.         Pascal  and  Modula-2 and are also of a fundamental  nature.
  22.         You  will  need  to study all of Part I in  order  to  write
  23.         meaningful Modula-2 programs.   If you are already a  fairly
  24.         experienced Pascal programmer, you will absorb this material
  25.         very  fast.   Be  sure  to go through it all at  least  once
  26.         because  there  are  many  small  differences  between   the
  27.         languages that you must consider.
  28.  
  29.                         MODULA-2 TUTORIAL - PART II
  30.  
  31.              The topics taught in Part II of this tutorial are those
  32.         advanced features that are also available in Pascal. Some of
  33.         these topics are pointers,  dynamic allocation, records, and
  34.         linked lists.  They are very powerful tools that can be used
  35.         to  great  advantage but are quite often overlooked by  many
  36.         Pascal  programmers that I have talked to.   These  are  the
  37.         tools   that  give  Pascal  and  Modula-2  an  advantage  in
  38.         flexibility over such languages as BASIC and FORTRAN.   They
  39.         do  require a bit of deep concentration to  understand,  but
  40.         you  will  be  greatly  rewarded if you  take  the  time  to
  41.         understand and use them.
  42.  
  43.                         MODULA-2 TUTORIAL - PART III
  44.  
  45.              Part  III  of  this tutorial covers  those  aspects  of
  46.         Modula-2 that are not included in Pascal in any way. Some of
  47.         the topics are independent compilation,  the entire topic of
  48.         modules,  and  concurrent processing.   These  are  advanced
  49.         topics  and some of these topics may be the reasons that you
  50.         selected Modula-2 as a programming language.   The  material
  51.         covered  in Part I in conjunction with that covered in  Part
  52.         III can lead to some very powerful programming techniques.
  53.  
  54.  
  55.  
  56.  
  57.                                    Page 1
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.                     Introduction to the Modula-2 Tutorial
  68.  
  69.  
  70.              To  efficiently use this tutorial,  you must  carefully
  71.         study  all of the material in Part I,  then you can do a lot
  72.         of  jumping around in Parts II and III and still  cover  the
  73.         material  in a meaningful manner.   You may also  choose  to
  74.         only  study some chapters of the last two parts in order  to
  75.         learn  the  needed material for the programming  problem  at
  76.         hand.   I  would like to emphasize that it is important that
  77.         you cover the material in Part I very carefully and in order
  78.         since so much depends on what was taught before.   When  you
  79.         get to the last two parts, comments at the beginning of each
  80.         chapter  will  tell  you what parts need to be  reviewed  in
  81.         order to effectively use the material in the chapter.
  82.  
  83.                         FOR THE BEGINNING PROGRAMMER
  84.  
  85.              If  you  are  a novice to  computer  programming,  this
  86.         course  is  for  you because it is  assumed  that  you  know
  87.         nothing about programming.  Many sections, especially in the
  88.         early  chapters,  will  cover  very basic  topics  for  your
  89.         benefit.   The biggest problem you will have will be setting
  90.         up your compiler for use, since this can be a very difficult
  91.         task.   Possibly you know someone with experience that would
  92.         be  willing  to help you get started.
  93.  
  94.                             FOR ALL PROGRAMMERS
  95.  
  96.              There  are,  at  this time,  a very limited  number  of
  97.         Modula-2  compilers available,  but it would not be possible
  98.         to  include notes on every compiler about how to install  it
  99.         for   your  computer.    The  COMPILER.DOC  file   on   your
  100.         distribution  disk contains notes on all of the compilers we
  101.         have  had access to and some of the difficulties in  setting
  102.         them  up for the IBM-PC or near compatibles.   In  addition,
  103.         all  compilers  do not implement all  functions  defined  in
  104.         Niklaus  Wirth's  definition of the language.   As  many  of
  105.         these  as  we  have  found  are listed  in  the  same  file.
  106.         Finally,  all of the problems in compiling the files on this
  107.         disk are noted in the COMPILER.DOC file.   It would be worth
  108.         your  effort  to print out this file and keep  the  hardcopy
  109.         handy while you are working your way through the lessons.
  110.  
  111.              Modula-2,  as  defined by Niklaus  Wirth,  contains  no
  112.         provisions  for input or output because they are so hardware
  113.         dependent.   It is up to each compiler writer to provide you
  114.         with supplemental procedures for handling I/O (input/output)
  115.         and a few other machine dependent features.   Niklaus  Wirth
  116.         did  recommend  a  library of I/O routines  that  should  be
  117.         available   and  most  compilers  contain  at  least   those
  118.         facilities, and usually provide many more.  The COMPILER.DOC
  119.         file   will   contain  notes  about  differences  in   these
  120.         facilities for those compilers which we have access to.  The
  121.  
  122.  
  123.                                    Page 2
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.                     Introduction to the Modula-2 Tutorial
  134.  
  135.  
  136.         COMPILER.DOC file will be updated anytime new information is
  137.         available.
  138.  
  139.                         SIMPLE EXAMPLES WILL BE USED
  140.  
  141.              All  of the instructional programs are  purposely  kept
  142.         simple and small to illustrate the point intended.  It is of
  143.         little  value  to  you to present you with a  large  complex
  144.         program  to  illustrate what can be illustrated in  a  small
  145.         program better.  In addition, every program is complete, and
  146.         can be compiled and run.   Program fragments frequently pose
  147.         as many questions as they answer.
  148.  
  149.              Because  it would be a disservice to you to teach you a
  150.         lot  of  simple techniques and never show you  how  they  go
  151.         together in a significant program, chapters 9 and 16 contain
  152.         several larger example programs.   A relatively small amount
  153.         of  description  is given about these programs  because  you
  154.         will  have already covered the details and only need a quick
  155.         overview of how to put the various constructs together.  You
  156.         will  find some of these programs useful and will  have  the
  157.         ability  to  modify and enhance them for your use since  you
  158.         have the source code.
  159.  
  160.                 SOME VARIABLE NAMES SEEM SILLY, WHY IS THAT?
  161.  
  162.              I  have  seen  example  programs  with  the  same  name
  163.         everywhere,  and  had  a hard time deciding what names  were
  164.         required  and  what  could  be  changed  to  something  more
  165.         meaningful.  For example a "SORT" program is in a file named
  166.         "SORT",  the program name is "SORT", the input file is named
  167.         "SORT", and variables were named "SORT1", SORT2", etc.  This
  168.         was no help to myself, a novice sorter, and would be no help
  169.         to  you.   For  that reason the first program is in  a  file
  170.         named "PUPPYDOG.MOD" and the module name is  "PuppyDog".  It
  171.         should  be  obvious to even the newest programmer  that  the
  172.         name  of  a  module can be anything if it is allowed  to  be
  173.         "PuppyDog".   You will learn later that well selected  names
  174.         can be a great aid in understanding a program.  This will be
  175.         evident  in  some of the early programs when variable  names
  176.         are chosen to indicate what type of variable they are.
  177.  
  178.              Some compilers require that the module name be the same
  179.         as the file name, and all require them to agree when you get
  180.         to  global  modules because of the way  "Type  checking"  is
  181.         accomplished.   It  would  be best for you to get  into  the
  182.         habit  of naming them both the same now.   For that  reason,
  183.         all  of the example programs use the same name for the  file
  184.         name  and for the module name.   Your compiler may allow you
  185.         to use different names.   It will be left up to you to study
  186.         your manual and see if this is so for your compiler.
  187.  
  188.  
  189.                                    Page 3
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.                     Introduction to the Modula-2 Tutorial
  200.  
  201.  
  202.  
  203.                             WHAT IS A COMPILER?
  204.  
  205.              There  are  two  primary methods used  in  running  any
  206.         computer  program  that  is written in a  readable  form  of
  207.         English.    The   first  method  is  an   interpreter.    An
  208.         interpreter  is  a program that looks at each  line  of  the
  209.         "english"  program,  decides what the "english" on that line
  210.         means,  and does what it says to do.  If one of the lines is
  211.         executed  repeatedly,  it must be scanned and analyzed  each
  212.         time,  greatly  slowing down the solution of the problem  at
  213.         hand.
  214.  
  215.              A compiler on the other hand,  is a program that  looks
  216.         at  each statement one time and converts it into a code that
  217.         the  computer  understands  directly.    When  the  compiled
  218.         program  is  actually run,  the computer does  not  have  to
  219.         figure  out  what each statement means,  it is already in  a
  220.         form  the  computer can run directly,  hence a  much  faster
  221.         execution  of the program.   Due to the nature of  Modula-2,
  222.         there will be few, if any, interpreters.
  223.  
  224.                    WHAT ABOUT THE PROGRAMMING EXERCISES?
  225.  
  226.              The  programming exercises at the end of  each  chapter
  227.         are a very important part of the tutorial.   If you do them,
  228.         you  will  embed the principles taught in each chapter  more
  229.         firmly in your mind than if you ignore them.   If you choose
  230.         to  ignore  them,  you  will be somewhat  adept  at  reading
  231.         Modula-2 programs but very ineffectual at writing them.   By
  232.         doing  the  exercises,   you  will  also  gain  considerable
  233.         experience in using your editor and compiler.
  234.  
  235.              It  will  be  assumed that you know  how  to  use  your
  236.         compiler  and  that you have some kind of an editor for  use
  237.         with the example files.  With the above in mind, you are now
  238.         ready to begin your tour of Modula-2.
  239.  
  240.              A sample program is included in this chapter for you to
  241.         try  with your compiler.   It is left as an exercise for you
  242.         to compile and run FIRSTEX.MOD.   When you can  successfully
  243.         compile  and  run this program,  you are ready to begin  the
  244.         tutorial on Modula-2 programming.   Do not worry about  what
  245.         the statements mean in FIRSTEX.MOD, you will have a complete
  246.         understanding  of  this  program by the  time  you  complete
  247.         chapter 4.
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.                                    Page 4
  256.  
  257.