Ada Lab Examples

Fifteen runnable Ada programs that follow the track's lesson order, grouped by phase. Every file is self-contained and fully commented. Compile them with GNAT (gnatmake file.adb — see the run notes at the bottom) or open them in the code viewer and change one thing, then compile again. That second run is where the learning happens.

Foundations

Hello world and the typed declaration discipline — the two files every later demo assumes you have seen.

#DescriptionLink
1Hello Ada — main procedure, context clause, Put_LineView
2Types and ranges — new types, subtypes, Constraint_ErrorView

Basic Constructs

Selection, repetition, text, and enumerations — the everyday logic vocabulary.

#DescriptionLink
3Conditionals — if/elsif and a compiler-checked caseView
4Loops — for, reverse, while, loop/exit, labelsView
5Strings — fixed, slices, unbounded growthView
6Enumerations — attributes, case coverage, representationView

Data & Logic

Arrays, records with variants, safe references, and decomposition into subprograms.

#DescriptionLink
7Arrays — aggregates, slices, enum-indexed arraysView
8Records — nesting, variant discriminants, defaultsView
9Access types — allocation, dereference, null safetyView
10Subprograms — modes, overloading, expression functionsView

Modular Systems

The first multi-file demos: a package with a private type, exception flow, and a generic container.

#DescriptionLink
11Package spec (geometry.ads) — private type + APIView
12Package body (geometry.adb) — the implementationView
13Client of the package + exception handlingView
14Exceptions — raise, propagate, messagesView
15Generics — a generic stack, instantiated twiceView

Advanced Paradigms

Tagged dispatch, contracts, concurrency, and the standard containers.

#DescriptionLink
16OOP — tagged types, overriding, class-wide dispatchView
17Contracts — pre/postconditions and predicatesView
18Tasking — tasks, protected bounded bufferView
19Standard library — Ada.Containers.Vectors and mapsView
How to run them. Compile straight from the demo folder: gnatmake demo/foundations/01_hello.adb then ./01_hello. The multi-file package pair compiles together: gnatmake demo/modular/12_package_main.adb (GNAT finds the spec and body automatically). Demos 3–14 need only GNAT; 17's delays make the interleaving visible; 18 needs any GNAT with the standard library. Larger multi-file study projects are on the Study Projects page.