Here are some main units of Ada:
The compiler can identify the root process of the file because of two reasons:
But the subprograms can be used bringing them into scope.
This is achieved by:
procedure main is
procedure foo [ is begin ... end foo ];
begin --main
...
end main;
[if definition was omitted, it goes here]
Having a file foo.adb with foo as the main process defined:
with foo;
procedure main is
begin --main
foo;
...
end main;
foo can be compiled separately.
These are quite like libraries in C, but they don't bring all the trash into scope with them.
They are intercommunicated modules, almost like independent programs, but with mechanisms of control.
For starters, you must define the interface, and then the module. This provides private/public separation.
Packages are also like classes (in c++ and Java), but better.
You can define any procedure or function in a body file (adb extension). And use with-use to call it at any point of your program.
You can call already built programs.
If you are interested in the economics of coding, this should be very interesting for you, as you can sell programs without sharing a line of code.
Also if you have to maintain a big project, as modulating the program will make things easier to maintain and upgrade.
hello.adb
with Ada.Text_IO; use Ada.Text_IO;
procedure hello is
begin
Put("Hello ");
end hello;
hello_name.adb
with Ada.Text_IO; use Ada.Text_IO;
with Hello;
procedure hello_name is
name: String(1..100);
Last: Natural;
begin
Get_Line(name,last);
Hello;
Put_Line(Name(1..Last));
end hello;
hello_name.adb
with Ada.Text_IO; use Ada.Text_IO;
procedure hello_name is
name: String(1..100);
Last: Natural;
procedure Hello;
-- Just declaration
begin
Get_Line(name,last);
Hello;
Put_Line(Name(1..Last));
end hello;
procedure hello is
begin
Put("Hello ");
end hello;
hello_name.adb
with Ada.Text_IO; use Ada.Text_IO;
procedure hello_name is
name: String(1..100);
Last: Natural;
procedure hello is
begin
Put("Hello ");
end hello;
begin
Get_Line(name,last);
Hello;
Put_Line(Name(1..Last));
end hello;
with Ada.Text_IO;
...
Ada.Text_IO.Put("Hi");
--In the header
with Ada.Text_IO;
...
-- In Declaration
package T_IO renames Ada.Text_IO;
...
--In body
T_IO.Put("Hi");
--In the header
with Ada.Text_IO;
...
-- In Declaration
use Ada.Text_IO;
...
--In body
Put("Hi");