Section 1.3 - Use Clauses
Some programs might be very wordy if you had to always specify
where a procedure is defined in order to use it.
Thus, Ada provides the use clause.
Whenever you use a procedure (or something else) but do not specify
where it is defined, the Ada compiler will search all units
listed in applicable use clauses.
Use clauses follow the with clause,
begin with the keyword use,
and then list the library units to be searched.
Here's how that first program would look with a use clause:
-- Print a simple message to demonstrate a trivial Ada program.
with Ada.Text_IO;
use Ada.Text_IO; -- use clause - automatically search Ada.Text_IO.
procedure Hello is
begin
Put_Line("Hello, world!"); -- Note: No longer has "Ada.Text_IO" in front.
end Hello;
Quiz:
If, in this new version of the program, you changed the second-to-last-line
back to:
Ada.Text_IO.Put_Line("Hello, world!");
would the program still work?
- Yes
- No
You may also:
Go back to the previous section
Skip to the next section
Go up to the outline of lesson 1
David A. Wheeler (wheeler@ida.org)