with Ada.Text_IO;
use Ada.Text_IO;
procedure Hello is
begin
-- This is a comment
-- Ada.Text_IO.Put_Line ("Hello world!"); -- When use is remove
Put_Line ("Hello world!"); -- Single Line comment
end;Programs in Ada usually use the .adb extension (ADa
Body). As with most other languages we’ve seen before, it’s
necessary to indicate the package that contains the function of
interest, something similar to the includes and
imports we’ve seen in other languages. In Ada, the
equivalent is with. The use clause simply adds
the definitions in the module to the namespace, so that
it’s not necessary to write the name of the package before the function.
This way, we can write Put_line, instead of
Ada.Text_IO.Put_Line… just as happens with C++.
As you can imagine at this point, Put_Line adds a
carriage return to the string we write on the screen, while
Put doesn’t. In general, the names used in Ada are very
descriptive as we’ve just seen. Perhaps C# took this idea from ADA?
The function (actually procedure in Ada jargon) Put_Line
allows us to write to the console and it is provided by the package
Ada.Text_IO as we have been able to check.
DID YOU KNOW
Ada has a syntax very similar to Pascal and Modula 2, two of the most important languages in the field of structured programming. Although it never became a popular general-purpose language, Ada is the choice for developing critical systems, both in the space industry and in the military field. And believe it or not, it’s still used today.
Comments in Ada are preceded by two minus signs -- just
like in Lua or SQL, and it is not possible to define multiline
comments.
As happens with Java, the entry point of the program must be a
procedure with the same name as the file that contains it. In our case,
the previous program must be stored in a file called
hello.adb.
Ada also does not allow defining multi-line strings. As happened with other languages, the best we can do is concatenate the chunks of string we want. Like this:
with Ada.Characters.Latin_1;
use Ada.Characters.Latin_1;
(...)
Put_Line ("We cannot use strings " & CR & LF
& "spreading through multiple lines " & CR & LF
& "directly " & CR & LF
& "-------------------------------");The package Ada.Characters.Latin_1 defines the constants
CR (Carriage Return or carriage return) and
LF (Line Feed or line feed).
To compile the program we will use the following command:
gprbuild hello.adb -o hello.ada.bin
or if we are using the Gnat package
gnat make hello.adb -o hello.ada.bin
The Ada language was originally developed by a team led by Frenchman Jean Ichbiah at CII Honeywell Bull under a contract with the United States Department of Defense (the famous DoD) between 1977 and 1983.
Ada was designed to develop embedded and real-time systems, and this remains its primary use today. As you can imagine, it takes its name from the first programmer in history, Ada Lovelace, Countess of Lovelace and legitimate daughter of Lord Byron, the famous British Romantic poet.
Summary
- Compiled language
- Extension:
adb - Line terminator: Carriage return
- Groups instructions with:
begin instructions end - Multiline comments: None exist
- Same line comments:
-- - String delimiter:
"string" - You can print texts with
Ada.Text_IO.Put_Line(Adds carriage return) - Support multiline strings: Not supported. Can concatenate strings
with
& - Does not support
HERE-DOCS - Entry point: Procedure with the same name as the file