1.4 Third Example: Do_Both

[ Table of Contents ] Prev ] Chapter Overview ] Next ] [ Glossary/Index ]

Im1-3.gif (3021 bytes)

In this example we employ the two preceding example programs as reusable components known as library units. Our main procedure, Do_Both, depends on these two library units.

The Say_Hello and Show_Date procedures are user-defined library units, which depend on the predefined library units shown at the bottom of the diagram.  The latter are library packages, the former are library procedures.

Once the new main procedure, Do_Both, has been compiled, it too becomes a library unit, which could be used again ("withed in") by another unit in another program. Thus, the program depicted graphically above consists of five library units: two from the predefined environment and three that have been user defined. In the next chapter you will see that whenever a program unit is created it falls into one of two categories: it is either a library unit or a nested unit.

Source Code Listing

--  This program calls two library procedures to, first,
--  display the message "Hello" and, second, to find and 
--  display the current date. 
with Say_Hello, Show_Date;    -- with clause
procedure Do_Both is
end Do_Both; 

If you compile and link the above program and then run it on say, November 2, 2002, the following lines of text should be displayed:

     Today's Date:
       Year = 2002
       Month = 11
       Day = 2

Note that there is only one with clause, which names two withed in library units (our first two example programs). Their names are separated by a comma. This is more compact, but equivalent to writing two separate with clauses.

[ Back to top of pagePrev ] Next ]