1.1 First Example: Say_Hello

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

IM1-1.gif (1934 bytes)

This diagram represents the architecture of our first example. The code is shown below. There are two Ada modules involved, a procedure named Say_Hello and a package named Ada.Text_IO. The latter is provided to us as part of Ada’s predefined environment.

The dashed arrow represents a dependency relationship between  the procedure and the package. That is, the procedure depends upon resources exported by the package. The other symbols are discussed in Chapter 2.

You can click on green elements of the diagram to jump to corresponding elements of code. Clicking on the green square in the upper left corner takes you to a point just above the code listing.

Source Code Listing

---------------------------------------------------------------
-- This program prints out the word "Hello"
---------------------------------------------------------------
with Ada.Text_IO;                 -- context clause
procedure Say_Hello is            -- procedure body starts here
begin 
  Ada.Text_IO.Put_Line("Hello");  -- procedure call
end Say_Hello;                    -- procedure body ends here
---------------------------------------------------------------

Comments

Note that a double-dash (--) marks the beginning of a comment (text ignored by the Ada compiler). Each comment ends with the end of that line of text.

Context Clauses

The first line of code is called a context clause, specifically a with clause.   It establishes the dependency relationship mentioned above. The procedure Say_Hello "withs in" (depends upon) the package Ada.Text_IO.

Executable Code

There is only one line of executable code in this example, the procedure call to the Put_Line procedure exported by the Ada.Text_IO package (pronounced "Ada-dot-Text-I-O").
Every sequence of executable lines of code is bracketed between the words begin and end.

Reserved Words

Note also that five words in the example are shown in bold font. These are some of Ada’s reserved words. Ada has 69 reserved words, which are listed in Appendix A. We will continue to follow this convention, showing reserved words as bold, and in lower case, in all Ada code listings.

Names: Rules and Style

The names (identifiers) of elements (such as the name Say_Hello) consist of letters of the alphabet (upper or lower case), decimal digits and underscores, with no spaces. The first character must be a letter. Underscores may occur only one at a time, neither first nor last. Ada is not case sensitive. It is conventional practice for many Ada programmers to use the style illustrated here, using upper case for the first character of each word in an identifier and lower case elsewhere.

Related Topics

2.4 Procedures 2.6 Packages 3.2 Procedure Calls
A.1 Reserved Words B.0 Predefined Environment

[ Back to top of pageNext ]