Copyright 1984 by ABComputing ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» º Ada - New Language in Town º º º º by º º º º George Gordon Noel º ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Introduction ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ I am a free lance writer, and have used Ada on a full-time basis for over one year. I am also a member of ADATEC, the professional society devoted to Ada. As Ada has the full support of the U.S. government, it is destined to become one of the most important programming languages of the last part of this century. It is my purpose to introduce you to this important language. If you have questions about Ada (or comments on this column), send them to PCFL and I will do my best to answer them. Your feedback is needed. This first column addresses the history and nature of Ada. A full Ada tutorial begins in the next issue of PCFL. Ada is a new language, and good tutorial literature is difficult to find. Those seriously studying Ada should subscribe to ADA LETTERS, the authoritative Ada journal. They should also consider joining ADATEC. Send inquiries regarding the ADA LETTERS or membership in ADATEC to the Association for Computing Machinery, 11 West 42nd St., New York, NY 10036. Ada was created by the United States Department of Defense ( DoD ) as a solution to a very costly problem. In typical bureaucratic fashion, different branches of the Pentagon used different computer languages to program embedded systems ( computers that live inside and control larger machines such as cruise missiles or space probes ). Government analysts realized that adopting one language as a common "tongue" could save the taxpayers a sizable amount of money. A committee (of course) was formed to draft a list of specifications for this common language. Existing languages such as Pascal and PL/1 were considered, but found inadequate. The Pentagon contracted a large multinational corporation, CII Honeywell Bull, to design a new language to their stringent specifications. The result was Ada. The name Ada is not an acronym like FORTRAN or BASIC. Ada was a nineteenth century British noblewoman - Augusta Ada, Countess of Lovelace. She assisted the pioneering inventor Charles Babbage in the development of his mechanical computer called the analytical engine. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Design Goals of Ada ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ The primary design goals of Ada were to provide a structured language, a portable language, and a modular language. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Structured Language ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ A structured language encourages well thought out, highly formalized programs. The syntax of Ada is very rigid, which restricts a programmer's freedom. This eliminates the sort of sloppy, bug-filled programming that comes naturally in non-structured languages such as BASIC or FORTRAN. (EDITOR'S NOTE: them is fighting words! ) The formality of Ada's syntax is to be expected as Ada has borrowed from another highly structured language: Pascal. In future columns, we will consider features of Ada that go far beyond anything in Pascal. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Portability ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ The second design goal was portability. As Ada is a trademark of the DoD, any language calling itself Ada must meet DoD standards. These standards are detailed in the "Ada Language Reference Manual" - unfortunately, one of the worst written documents in the English language. ( If you are serious about Ada, though, you should own a copy. Order it from ADATEC at the address given above.) There can be no deviations from the standard - no subsets, supersets, dialects, or variants. When a compiler meets the standard, it is submitted to the DoD for "validation." Ada programs written on one computer can be moved to another machine without translation. This type of standardization was one of the original advantages of Pascal, although the weaknesses in that language have spawned a number of dialects that are incompatible with each other. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Modularity ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ The last major design goal of Ada is modularity - the ability to break a large program into smaller, more easily managed parts (top-down programming) or to assemble small, pre-compiled modules into one large program (bottom-up programming). Other languages have this ability. In FORTRAN, independently compiled subroutines can be linked to form one large module. But, modularity in Ada far exceeds anything I have seen in other languages. This is because Ada has a dual nature - it is part compiler and part data base manager. When a program is compiled, Ada places it in a data base called a "program library" where it waits patiently until it is needed. Since this is the part of Ada that excites me the most, we will use it as a springboard for our first example. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Example Program ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ When an Ada compiler is purchased, a program library containing several packages is included. One package is the module TEXT_IO, which contains the tools for doing input and output with text characters. ( I/O routines are not an intrinsic part of Ada as they are in most languages.) If I/O routines are needed, the TEXT_IO module must be retrieved from the program library. This is done using an Ada command called a "with clause," consisting of the word "with" followed by the name of the module to be retrieved from the program library. Our first Ada program has a "with clause" as a heading. It is an example of a "procedure," an Ada program unit similar to the subroutines of PL/1, FORTRAN, and a host of other languages. with TEXT_IO; procedure MESSAGE is use TEXT_IO; begin put ("How are things going so far?"); end MESSAGE; Ignoring the "with clause" and some syntactical curiosities (such as the "use clause" in line three), this could be Pascal or any number of modern languages. As we have not begun our tutorial, do not be concerned with the pieces of the language you don't understand. When the program is compiled and run, it prints the message: How are things going so far? The input/output of this program is done by the "put" procedure in line five, which prints a string. Before the "put" procedure can be used, it must be retrieved from the TEXT_IO module in the program library. This is accomplished by the "with clause." When the Ada compiler encounters "with TEXT_IO" it acts like a data base manager, searching the program library until TEXT_IO is found. Upon locating the module, the compiler makes all the resources inside the module (including the "put" procedure) available to the MESSAGE program. All compiled programs are placed in the program library. The MESSAGE example program is there now, and can be retrieved using the "with clause," just as we did for TEXT_IO. with TEXT_IO, MESSAGE; procedure ADA_SENDS_HER_GREETINGS is use TEXT_IO; begin put ("The Countess asks `"); MESSAGE; put ("'"); end ADA_SENDS_HER_GREETINGS; Compiling and running this program results in the display: The Countess asks `How are things going so far?' I hope the answer is "Fine". This question from Lady Lovelace brings us to the end of the first column. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Conclusion ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ Those hungry for more are invited to dine on the source code in the "Ada Programs" section of this column. One program is a sort program, and the other finds the greatest common divisor of two integers. The latter routine is intended as a demonstration of Ada's "package" facility. The nitty-gritty details needed to understand Ada will begin pouring in, in the next issue of PCFL. ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ File Name: ÛÛ ada1.txt ÛÛ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÄÄÄ¿ 6. ³ Save, print or graph worksheet ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ