Ada: Standard Library
The Ada standard defines the library with the language — Ada.* namespaces are portable across every compiler. This tour covers the three families you will use constantly: containers, numerics, and the string/character utilities.
Containers
Ada.Containers provides generic, type-safe collections. They are formal packages — you instantiate them for your element type, and every operation is checked:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
procedure Container_Demo is
-- a vector of unbounded strings: Positive is the index subtype
package Name_Vectors is new Ada.Containers.Vectors
(Index_Type => Positive, Element_Type => Unbounded_String);
use Name_Vectors;
Names : Vector;
begin
Names.Append (To_Unbounded_String ("Ada"));
Names.Append (To_Unbounded_String ("Jean"));
Names.Append (To_Unbounded_String ("Tucker"));
-- iterate with a cursor or a plain loop over the index range
for I in Names.First_Index .. Names.Last_Index loop
Put_Line (To_String (Names (I)));
end loop;
Put_Line (Natural'Image (Length (Names)) & " names");
end Container_Demo;
The family covers the standard structures — all with the same instantiate-then-use pattern:
| Container | Package | Notes |
|---|---|---|
| Vector | Ada.Containers.Vectors | growable array, O(1) index |
| Doubly linked list | Ada.Containers.Doubly_Linked_Lists | stable cursors, O(1) splice |
| Hashed map | Ada.Containers.Hashed_Maps | key → element, user hash |
| Ordered map | Ada.Containers.Ordered_Maps | sorted traversal, no hash needed |
| Sets | Hashed_Sets, Ordered_Sets | membership, set algebra |
| Queues | Unbounded_Priority_Queues | tasking-ready priority queues |
Cursors (Container.First, Next (C)) traverse without invalidating on append for lists; vectors invalidate on reallocation — the docs state which operations invalidate, precisely.
Numerics
Ada.Numerics supplies math with precision control — the Elementary_Functions generic works for any float precision you define:
with Ada.Numerics.Elementary_Functions; use Ada.Numerics.Elementary_Functions;
with Ada.Text_IO; use Ada.Text_IO;
procedure Numerics_Demo is
begin
Put_Line (Float'Image (Sqrt (2.0))); -- 1.41421...
Put_Line (Float'Image (Sin (Ada.Numerics.Pi / 2.0))); -- 1.0
Put_Line (Float'Image (Ada.Numerics.Pi)); -- pi as a constant
end Numerics_Demo;
Two other families matter for engineering code: Ada.Numerics.Discrete_Random / Float_Random (typed random number generators — results land in your range type, not a magic int) and Ada.Numerics.Generic_Complex_Types (complex arithmetic for any real type).
Strings and Characters
Ada.Strings and Ada.Characters complete the text toolset introduced in the Strings lesson: Fixed (in-place operations on fixed strings), Maps (character sets and translation functions), case conversions via Ada.Characters.Handling, and Ada.Characters.Latin_1 constants (Latin_1.NUL, Latin_1.HT…).
Other Keepsakes
Beyond containers, numerics, and text utilities, the standard library includes portable system packages for timekeeping, file systems, CLI arguments, C interop, and runtime assertions:
Ada.Calendar— a typed time/date library;Ada.Real_Timefor monotonic real-time clocks in tasking code.Ada.Directories— portable file-system queries and operations.Ada.Command_Line— arguments and exit status.Interfaces.C— the typed C interop layer.Ada.Assertionsand pragmaAssert— executable checks that contracts formalize.
Everything in Ada.* is defined by the Reference Manual, so behavior is identical from GNAT on Windows to a cross-compiler for a flight board. Next: Lab Examples.