Skip to main content
Background image of Earth and satellite
Background image of Earth and astronaut

Ada Programming Language

A programming language for readable, correct, and performant software.
Get started with Alire, the Ada package manager.
1
with Ada.Text_IO;
2
3
procedure Main is
4
type GUID is new String (1 .. 32)
5
with Dynamic_Predicate =>
6
(for all C of GUID => C in '0' .. '9' | 'a' .. 'f');
7
8
ID_1 : constant GUID := "030000004c050000cc09000011810000";
9
begin
10
Ada.Text_IO.Put_Line ("Reading from device " & String (ID_1) & "...");
11
end Main;
1
with Interfaces;
2
3
package Xoshiro128 with Pure, SPARK_Mode => On is
4
use type Interfaces.Unsigned_64;
5
6
type Generator is limited private;
7
8
procedure Next (S : in out Generator; Value : out Interfaces.Unsigned_32)
9
with Global => null,
10
Depends => (S => S, Value => S);
11
12
procedure Reset (S : out Generator; Seed : Interfaces.Unsigned_64)
13
with Global => null,
14
Depends => (S => Seed),
15
Pre => Seed /= 0;
16
17
private
18
type Generator is array (0 .. 3) of Interfaces.Unsigned_32;
19
end Xoshiro128;
1
with RP.GPIO;
2
with Pico;
3
4
procedure Main is
5
begin
6
Pico.LED.Configure (RP.GPIO.Output);
7
loop
8
Pico.LED.Toggle;
9
delay 0.1;
10
end loop;
11
end Main;
Ada

Readable, correct, performant

Express intent with explicitness, describe properties with predicates and pre/post conditions, and import C/C++ functions or intrinsics.
Readable

Express intent with explicitness and keywords over symbols and special structures.

Express concepts like meaning in integers. Use built-in design by contract with pre/post-conditions and invariants. Model problems with typechecks and range constraints.

Correct

Build with technology used in 40 years of reliability in planes, trains, and satellites.

Use the SPARK subset to formally verify part or all of your program, and integrate existing SPARK crates available in the Alire package manager.

Performant

Build native applications and take advantage of other libraries through binding to C and C++.

Use inline assembly or compiler intrinsics when you need it. Control resources with scope-based resource control (RAII) and your own memory allocators.

Set-up environment

Package manager + toolchain

Download the Alire package manager and install the compiler.
Download Alire
Download Alire v1.2.1.
Install toolchain
alr toolchain --select
Select gnat_native and gprbuild.
Start coding
Create a crate:
alr init --bin mycrate && cd mycrate
Build the crate:
alr build
Run your application
alr run
SPARK

From memory safety to functional correctness

Gradually adopt the SPARK subset to reach various levels of assurance. Higher levels take more effort, but give more benefits and stronger guarantees.
Valid SPARK
Restrict Ada packages to the SPARK subset. Avoids side-effects in functions and parameter aliasing.
Initialization and correct data flow
No uninitialized variables are read or undesired access to globals occurs.
Absence of run-time errors
No buffer and arithmetic overflow, division by zero, or values out of range, among others, can occur.
Key integrity properties
Verify integrity of data and valid state transitions.