Pages

Wednesday, September 19, 2012

AdaTutor - Advanced Topics

Packages Standard and Ada.Characters.Latin_1

Ada comes with a package Standard. However, unlike all the other
packages, Standard is needed by every Ada compilation unit.
Therefore, Standard is automatically withed and used in every
compilation. It need not be mentioned in a context clause.
Standard contains the definitions built into the Ada language, such as type
Boolean is (False, True);. A listing of the package specification is
in Annex A.1 of the
Ada 95 RM. Thus, the full name for the type Boolean is Standard.Boolean,
the full name for Integer is Standard.Integer, etc. Naturally, this
normally need not concern the programmer. The dot notation is automatic
because Standard is automatically used in every compilation.

Ada 95 has a package Ada.Characters.Latin_1, defined in
Annex A.3.3 of the
Ada 95 RM. This package gives names to all of the unprintable 8-bit
characters, and some of the printable ones. For example, the unprintable
"bell" character is named BEL. If our program withs and uses this package and
Ada.Text_IO, then Put(BEL); will beep the terminal.

Ada 83 doesn't have Ada.Characters.Latin_1, but it has a package ASCII inside
package Standard. This package gives names to all of the unprintable ASCII
characters and some of the printable ones. (The ASCII characters are the first
128 of the 256 8-bit characters.) Ada 95 also has package ASCII for
compatibility, but with Ada 95 it's better to use Ada.Characters.Latin_1.

Since ASCII is inside Standard, we never have to write a with clause for it.
But ASCII isn't automatically used. If we want the dot notation for ASCII to
be automatic, we have to provide a use clause.

An Alternative to Infix Notation, and Use Type

An alternative notation equivalent to F := A * B; is F := "*"(A, B);. Why
would anyone want to use this clumsier notation? If our function is in a
package Math that the calling program withs but for some reason doesn't use, we
could use dot notation and write F := Math."*"(A, B);. But we couldn't use dot
notation directly with infix operators, as in F := A Math.* B; or even
F := A Math."*" B;. Both of those are illegal. The alternative notation can
also be used to emphasize that an operator comes from package Standard. For
example, if I, J, and K are Integers, we could write I := Standard."*"(J, K);,
which is equivalent to I := J * K;.

In Ada 95, a context clause can say use type, followed by the name of a type
or subtype in a package. This makes the dot notation automatic only for infix
operators for that type or subtype. For example, if we have a package Math
containing the definition of a type Vector and a * operator for Vectors, as
above, we can write

Here we were able to write F := A * B; instead of F := "*"(A, B); or
F := Math."*"(A, B); because we said use type Math.Vector; and the * here is
an infix operator for that type. However, in declaring A and B, we still had
to write Math.Vector, because use type applies only to infix operators for the
type or subtype named.

Question

Assuming X, Y, and Z have been declared Float, which one of the following is
illegal?