This program doesn't do anything except demonstrate Ada declarations. The
statement I, J, K : Integer; brings three integer variables into
existence.
The next statement creates two more integer variables and initializes both of
them to 30. Every time this procedure is called, L and M are brought into
existence and initialized to 30. This is different from a Fortran DATA
statement, which initializes only once at compile time.

The statement F, G : Float; creates two variables of type Float.
The next statement names a constant. Writing Factor is thereafter
equivalent to writing 1000. Unlike variables, constants must be initialized.

The first two executable statements are simple assignment statements. The
symbol := is read "becomes" or "gets." It may not contain a space.
In the
third executable statement, the compiler will reject the expression F + L
because Ada won't let us accidentally mix different types (Float and Integer).

However, Ada lets us deliberately mix types. The statement G := F + Float(L);
is legal because it converts L from Integer to Float, adds it to F which is of
type Float, and stores the result in G, also of type Float.
Likewise, the next
statement is legal because it converts F to Integer, adds the Integer L, and
stores the result in the Integer K. But note that when a Float is converted to
Integer, it's rounded, not truncated. (Later we'll learn how to truncate to
integers.) The last executable statement is illegal because a constant can't
appear on the left side of an assignment statement.

No, N is declared locally within Try_Me. So N is brought into existence and
initialized to 1 each time the procedure is called, and the procedure will
display 1 each time. Also remember that N goes out of existence when Try_Me
returns, so the statement N := 2; has no effect.

Enumeration Types

In Ada we can declare enumeration types, where we enumerate every possible
value for a type. For example, if we declare

then Rc can have any of 7 values. In the executable region we might write
Rc := Red; and we could also test: if Rc = Red then ... end if;.
The enumerated values, enclosed in parentheses and separated by commas, must follow
the rules for Ada identifiers, or they can be single characters enclosed in '
marks (called "tic" marks), thus:

type Even_Digit is('0','2','4','6','8');

It's illegal to write type Processor is (80486, Z80, 1750A);
because two of the
values aren't legal Ada identifiers. However, it's OK to mix characters and
identifiers in the same declaration, thus:

Rc could have any of 7 values, and Tc could have
any of 3 values. The compiler will have no trouble compiling

Rc := Red;
Tc := Red;

Because it knows that in Rc := Red;, Red must be the Rainbow_Color if it's
stored into Rc, and in Tc := Red;, Red must be the Traffic_Light_Color if it's
stored into Tc. The compiler knows that the types across := must always match.
Naturally, it's illegal to write Rc := 2;, because of the mixed types.

Also, if we have a procedure Display that takes one parameter of type
Rainbow_Color, the compiler could handle Display(Red); because it knows that
Red must be the Rainbow_Color to fit the procedure.

But if we had a procedure Display that takes a Rainbow_Color and a
Display that takes a Traffic_Light_Color, the statement Display(Red);
would be ambiguous;
the compiler wouldn't know which Display to call. In that case we could
specify the type by qualifying the name Red, writing Rainbow_Color'(Red). Note
the ' with the parentheses. The call would be Display(Rainbow_Color'(Red));.
The statements Display(Violet); and Display(Amber); aren't ambiguous;
the compiler will figure out which Display to call in these cases.

Declaring an enumeration type not only defines equality for objects of that
type, but also an order for the values. Thus we can check for , <=, etc.
For example, if we declare A, B: Rainbow_Color; and later write, in the
executable region, A := Yellow; and B := Blue; then the test A < B will turn out to be True. Yellow is considered less than
Blue.

We can input and output enumeration types by instantiating the generic package
Ada.Text_IO.Enumeration_IO. For example:

with Ada.Text_IO;use Ada.Text_IO; ...package My_Rainbow_IO is new Enumeration_IO(Rainbow_Color);use My_Rainbow_IO;

Since the above two declarations are built into the Ada language, they
shouldn't be repeated in your programs. Note that type Boolean is just an
enumeration type. The relational operators =, >, <=, etc. all return results
of type Boolean.

The definition of type Character can't be completely written out, because some
characters are unprintable . Here we've denoted such characters with names in
parentheses, and also used "..." for brevity. However, the type Character
contains all 256 possible 8-bit values. (In Ada 83, it contains only the first
128 values, corresponding to the ASCII characters.) Ada 95 also provides a
type Wide_Character, containing all 65,536 16-bit values, and a package
Ada.Wide_Text_IO.

You're right! Enumeration types can contain single characters between ' marks,
and Ada identifiers. Number 1 is illegal because it contains Strings, number 2
is illegal because ' marks may enclose only single characters, and number 3 is
illegal because an Ada identifier can't begin with a digit.