On this page
Vada units, subprograms and generics
A compilation unit is a library package/subprogram declaration or body, preceded by its context clauses. A file can be parsed as several compilation units, but project discovery and name/file matching still apply. Use the documented unit filenames rather than treating a directory as an order-dependent script.
Context clauses and visibility
with Ada.Text_IO;
with Counters;
use Counters;with makes a library dependency available. use permits declarations to be found without their package qualification. Without a use clause, write Counters.Next(41). Several units can be named with commas in one context clause.
use type T; makes a type's relevant operators directly visible. use all type T; also exposes the applicable primitive operations. These clauses do not copy a package or change ownership.
private with P; makes P available to the package's private part and body only. limited with P; is accepted where it forms no cycle and then means with P;; packages whose specifications name each other are a cycle (B1006) even with limited with. Move shared declarations into a third package or move implementation-only dependencies to a body. See program structure.
Context pragmas precede the library declaration. Elaborate and Elaborate_All can constrain dependency elaboration as supported. Verada computes an elaboration order and checks initialization; source listing order is not a substitute.
Specifications, bodies and private parts
package Names is
function Length return Natural;
private
Count : Natural := 0;
end Names;A package specification contains public declarations, followed optionally by a private part containing hidden declarations and completions. A package body supplies bodies and private implementation declarations:
package body Names is
function Length return Natural is (Count);
end Names;These together form a complete declaration/body pair with no main program. A body may contain begin followed by proved elaboration statements and optional exception handlers. If it has no elaboration statements, omit begin. An aspect list precedes is on package specifications and bodies, for example package P with Pure is ....
A child unit uses a selected defining name, such as package Parent.Child is .... A private child adds private before its library declaration. Parent/child visibility is defined by shared program structure; nesting names does not create arbitrary access to another unrelated package's private state.
Main programs
A normal main unit is a library-level parameterless procedure:
with Ada.Text_IO;
procedure Main is
begin
Ada.Text_IO.Put_Line ("Hello");
end Main;The unit's body may contain local declarations before begin. Do not declare global executable statements outside a unit. Main selection, project files and source discovery are toolchain responsibilities. run and build start at the one library procedure without parameters that no other unit names; a program with none, or with several, is B7014. The compiler does not require every file in a project to be a main program.
Profiles and parameter modes
function Clamp (Value, Low, High : Integer) return Integer;
procedure Add (Count : in out Natural; Amount : Natural := 1);
procedure Find (Key : Integer; Found : out Boolean);A profile separates groups with semicolons; names within a group use commas. An omitted mode is in. A function adds return and its result type/subtype mark. A function result is not a general mutable local variable named after the function; use return Expression;.
| Mode | Source behavior and obligation |
|---|---|
in |
Caller supplies a readable input; the formal cannot be assigned as an output |
out |
Callee establishes the output before it is used/returned as required |
in out |
Caller supplies initialized state, and the callee may change it |
An out/in out actual must be a writable object of a compatible subtype, not a literal or arbitrary expression. Vada does not put an ampersand on mutable actuals. Alias restrictions prevent incompatible overlapping uses even if each actual is individually writable.
Default parameter expressions use := in the declaration. A caller may omit a defaulted actual; the selected default is still subject to typing, effect and proof rules. Formal parameters can have supported aliased/not null access-related properties.
A parameter can be an anonymous access-to-subprogram, which the body calls like the subprogram itself:
procedure Apply (Op : not null access procedure (X : in out Integer);
V : in out Integer);The actual is 'Access of a subprogram declared in a package or at library level, as in Apply (Ops.Bump'Access, Total); its precondition must hold for every call the profile allows, since the callee calls it without knowing which subprogram it is.
Calls use positional actuals followed by optional Name => Value actuals. Procedures are called as statements; functions are used where a value is expected. A no-parameter procedure call is Reset;, and a no-parameter function use is Length rather than Length().
Bodies and declaration variants
A normal body places declarations between is and begin, statements after begin, and optional handlers before end:
function Name (parameters) return Type [with aspects] is
declarations
begin
statements
exception
handlers
end Name;
The exception part is optional. A declaration without a body ends after its profile and aspects with ; and must be completed where required.
An expression function uses one parenthesized expression:
function Double (Value : Integer) return Integer is (Value * 2)
with Pre => Value in -1000 .. 1000;For an expression function, aspects follow the expression, immediately before the semicolon. For a normal body, aspects can follow the profile before is. Moving the same with Pre mechanically between these placements is a syntax error.
A null procedure is procedure Ignore (Value : Integer) is null;. An abstract function/operation is declared ... is abstract;. These declarations can have their permitted aspects after null/abstract and before ;. An abstract operation needs the appropriate tagged/interface context.
Subprogram renaming uses renames Existing_Name in place of an implementation. The name may also be an operator, renames "+" or by its expanded name renames P."+" (which names the predefined operator of P's types without a use clause), or an enumeration literal, a function of no parameters (function Teal return Color renames Blue;); a call of such a renaming is the operation itself, checked where the call is. A call through a renaming names and defaults its parameters as the renaming declares them, whatever the renamed subprogram calls them; so does a call of a generic formal subprogram in an instance, by the formal's names. Overriding indicators precede function/procedure: overriding requires an actual override, while not overriding rejects an accidental one. A defining operator name is a quoted operator symbol such as function "+" (L, R : T) return T;.
A nested subprogram can appear in a declarative region. Recursion and termination need appropriate variants/contracts. Contract-free nonrecursive local helpers may be proved at their call sites; a public contract boundary should be explicit when modular reasoning is intended. Nested subprograms cannot be taken as arbitrary callback values.
Separate subunits
A body stub marks the body to be supplied elsewhere:
procedure Worker is separate;Its subunit begins with the parent's name:
separate (Parent)
procedure Worker is
begin
null;
end Worker;These are paired context fragments: Parent must contain the stub. A package body can similarly use package body Inner is separate;. Subunits share the appropriate enclosing visibility and still participate in unit/file, elaboration and proof checks. They are not a textual include mechanism: a subunit has its own context clause (with Ada.Text_IO; before separate (Parent)), and the units it names are loaded for it.
A subunit lives in its own file named after its parent and itself: Main.Report is in main-report.vadb. veradic run main.vadb finds it there without a project; a stub whose subunit file is missing is B1003.
Generic declarations
A generic declares type/value/operation parameters for a package or subprogram. Those formal parameters are supplied when making an instance. For example:
generic
type Item is private;
function Choose (First : Boolean; Left, Right : Item) return Item;Its body repeats the subprogram profile without repeating generic:
function Choose (First : Boolean; Left, Right : Item) return Item is
begin
if First then
return Left;
else
return Right;
end if;
end Choose;These are generic declaration/body fragments, to be placed in their matching library units or enclosing package. An instance for Integer is:
function Choose_Integer is new Choose (Item => Integer);A generic subprogram can also be declared, completed and instantiated inside a subprogram's declarative part, and its body can be an expression function or a null procedure. Inside a generic unit, the generic's own name denotes the current instance, so Counters.First in Counters names the instance's First, and Counters.Capacity its actual for a formal object Capacity. Any enclosing subprogram's name is a prefix in the same way: Main.Offset names the Offset declared in Main.
A package instance uses package Name is new Generic_Name (...);. A procedure instance uses procedure Name is new Generic_Name (...);. The instance's concrete profile comes from the generic; an instantiation does not repeat it.
Formal parameter families
| Generic formal | Example form |
|---|---|
| Discrete type | type Index is (<>); |
| Signed integer | type Count is range <>; |
| Modular | type Word is mod <>; |
| Floating point | type Real is digits <>; |
| Ordinary fixed point | type Fixed is delta <>; |
| Decimal fixed point | type Money is delta <> digits <>; |
| Private or limited private | type Item is private; or type Item is limited private; |
| Array/access/derived type | Corresponding supported type definition with formal marks |
| Input object | Capacity : Positive; |
| Object with default | Capacity : Positive := 100; |
| Formal function | with function Less (L, R : Item) return Boolean is <>; |
| Formal procedure | with procedure Apply (X : in out Item); |
| Formal package | with package P is new G (<>); |
Formals can include permitted use clauses and pragmas. Formal operations can have a named default; <> asks for the visible matching operation, and supported null procedure defaults use is null. Formal package actuals can be explicitly constrained or boxed.
Generic actuals must satisfy formal categories and profiles. Proof of an instance uses concrete actuals and declared operation contracts; a default operator is not a proof of its arbitrary implementation.
See shared generics for instance identity, proof boundaries and implicit instances introduced by other syntaxes. Vada's source spelling is explicit instantiation; a translator may emit a generated instance unit for Varc/Vibe conveniences.
Interfacing and source organization
Foreign subprograms use ordinary declarations with aspects such as Import, Convention => C and External_Name => "symbol". An imported declaration has no Vada body; its contract is trusted. Export exposes a defined operation at a foreign boundary without proving that arbitrary foreign callers satisfy its precondition.
Files normally follow lowercased unit names with dots changed to dashes: Parent.Child uses parent-child.vads and parent-child.vadb. A complete project can mix Vada, Varc and Vibe units, but duplicate declarations or incompatible spellings/instances do not become legal merely because they came from different frontends.