Computer Languages A to Z: Pascal

by Gary L. Ratliff Sr. (eronstuc)

Introduction to Pascal

The language Pascal was developed by Niklaus Wirth. He has already been mentioned as developing other languages, Modula 2 and Oberon 2. Were this not enough, he was also instrumental in developing the language ALGOL. However, there was quite a bit of difficulty in developing compilers for it, soit remained a language to formally state the algorithms for solving various computer problems, instead of a language used to develop software.

However, I remember that a system for ALGOL was available back when I was using a Kaypro and CP/M. Here it was possible to purchase, for very low fees, libraries from Sound Potential and other companies. Also, using NZ and the Z systems, it was possible to run the applications from a system in which the files were compressed on the hard drive and only expanded when the file was run. While serving as moderator on the CP/M group of the Intelec Network, one of the great debates was that Borland denied writing a Turbo Pascal for the CP/M operating system. So I loaded my CP/M CDROM from Walnut Creek and performed a search on ALGOL and Pascal, which verified that there was a version or two of ALGOL available for this system, and yes, there were many many systems developed for CP/M using Turbo Pascal.

Now Wirth was writing the specifications for the language Pascal at about the same time I was taking my first computer language course in Fortran at Delta State. The language was introduced to the computer world the same year I got married and earned my BBA degree, and the language was introduced by Wirth in 1971. It was easy to learn and was used mainly as a device to teach students to program. The back cover of one of the text books I used in researching this article: Introduction to Pascal and Structured Design, Second Edition by Nell Dale and Chip Weems © 1987 D. C. Heath and Company states that: "Over a quarter of a million students have been introduced to problem solving and good programming techniques with the first edition of Pascal."

Wirth received the A. M. Turing Award in 1984 "for developing a sequence of innovative computer languages: EULER, ALGOL-W, MODULA, and PASCAL." The Turing award has been awarded annually since 1966, and is the "highest distinction in Computer Science the Nobel Prize in computing." Since 2007 this award has been accompanied by $250,000 cash provided by cosponsors Intel and Google. Other persons who have received this award who have also been mentioned in this series were John Backus, who won in 1977 for Fortran, and Ken Iverson, who won in 1979 for APL.

Getting a compiler and other tools

The PCLinuxOS repository has several tools which will enable you to compile and develop software in the Pascal language. Also, many of the tutorials mentioned will have links to enable you to download compilers for Pascal and other development tools for this language. Many of these will be specifically for Windows. However, my stance on the matter is that there is a good chance that your computer also has Windows installed (or you have access to a computer running Windows), so why not go ahead and use this part of your computer to develop your programming skills and knowledge.

The tools will be obtained using the synaptic package manager. As always, you will become root to perform the install task.

The systems we will be installing from the repositories are: FPC (the Free Pascal Compiler), Lazarus (a graphic IDE for developing Free Pascal code), and the gtk editor scite. This editor is useful for its ability to correctly indent and color code the syntax of a Pascal program as it is entered. It is not only this language for which this editor provides these services, but also a vast assortment of many computer languages and shell programming languages.

Tutorials: We have Tutorials

There are a vast number of tutorials available, and they may be found by entering Pascal Tutorial into the search window of your Firefox browser. So we will just present an array of snapshots taken from the web pages of some of the best tutorials found:

pic

The above page shows links to several tutorials, which aid one in programming with the pascal language. The version of the language which is regarded as the king of the hill is the Borland Turbo Pascal compiler. This is the one which the Free Pascal Compiler tries to closely adhere to.

pic

This page as stated is devoted to teaching you programming using Borland Turbo Pascal. It offers to download the most recent version, which Borland has made freeware. However, this is a zip file and will download to your Download folder in My Documents under Windows. This is not where the install.exe program will want to use it. So first, move it to the root directory and let the install create the TP directory. It would be run by opening a command prompt in Windows, and then changing to the root directory and then to TP.

pic

This page shows that it covers Free Pascal, Turbo Pascal and Pascalite. I was able to download this but later attempts to further study this site only produced the Error 404 for site not found.

pic

This has been found to be an excellent tutorial. It assumes no prior knowledge of programming and is very easy to follow.

pic

As you can plainly see, there is an abundance of sources for you to learn the language. Now we have the Free Pascal Compiler on our system. The following is an example of code from the text I used, along with some praise for the folks at freepascal.org. The book I was using was written before some rather large changes were made. So as long as I did not try to use text files, these would compile, or they would show me my typos and I would try again. But even with the program typed in perfectly, the program would compile but report an error 102 when run. So I emailed my problem to michael@freepascal.org and had a reply with the remedy within hours.

The files used as text first required an Assign and then also needed to be closed before the program finished. Here is an example, which was saved in the scite editor to also show the indentation and color coding of the Pascal syntax.

pic

So now, with these corrections supplied by Michael Van Canneyt, the program compiled and the data was stored in the file outmpg for reading, via the command less outmpg. This indicated that the folks at the free pascal site are very helpful. Also, by visiting their site, you can download full documentation for the Free Pascal compiler in pdf format. Simply click on the documentation link.

Some folks think that Pascal has become obsolete. However, Michael assured me in his email that he uses it to create games, databases and other major projects, and that it is alive and well. It has also added some object orientated features. I hope this will encourage you to try to add Pascal programming to your arsenal.

Pascal and Structured Programming

(added by Patrick G Horneker)

Pascal has always been a language for teaching of structured programming and other good programming practices. One of the first things that Pascal forces programmers to do is to think about the design of the program, specifically that the program should be designed from the top down, with the top being the primary objective of what the program is to accomplish. Once that program is broken down into steps, you then break those steps into smaller steps, until you get to the minute details.

Programs in Standard (ISO) Pascal have only one entrance and one exit. This concept is true whether you are implementing the main portion of the program, or a subroutine to access a file on a disk.

One advantage to using Pascal for applications is that a top-down design and a concept of structured programming results in software that is reliable and quality controlled.

If you used only ISO Pascal for your DOS applications, chances are that your applications can be ported to PCLinuxOS with a minimum of work (depending on whether you are using a text-mode application, or are using bindings for Gtk, Qt, or some other graphical interface toolkit.) Windows applications in this language, however,will require some work, specifically rewriting subroutines that call Windows specific functions to subroutines that call functions for X, Gtk, Qt, or whatever graphical toolkits are available for FreePascal.