4.3.4 Delta Aggregates
Evaluating a (record or array) delta aggregate yields
a composite value that starts with a copy of another value of the same
type and then assigns to some (but typically not all) components of the
copy.
Syntax
Name Resolution Rules
The expected type for a
record_delta_aggregate
shall be a single descendant of a record type or record extension.
Legality Rules
Dynamic Semantics
if the associated component belongs to a
variant,
a check is made that the values of the discriminants are such that the
anonymous object has this component.
The exception
Constraint_Error is raised if this check fails.
the index value is converted to the index type
of the array type.
a check is made that the index value belongs to
the index range of the anonymous object of the
aggregate;
Constraint_Error is raised if this check fails.
the component
expression
is evaluated, converted to the array component subtype, and assigned
to the component of the anonymous object identified by the index value.
Examples
Examples of use
of delta aggregates in a postcondition:
procedure Twelfth (D :
in out Date) --
see 3.8 for type Date
with Post => D = (D'Old
with delta Day => 12);
procedure The_Answer (V :
in out Vector;
A, B :
in Integer) --
see 3.6 for type Vector
with Post => V = (V'Old
with delta A .. B => 42.0, V'First => 0.0);
Examples where the
base expression is nontrivial:
New_Cell : Cell := (Min_Cell (Head)
with delta Value => 42);
--
see 3.10.1 for Cell and Head; 6.1 for Min_Cell
A1 : Vector := ((0 => 1.0, 1 => 2.0, 2 => 3.0)
with delta Integer(Random * 2.0) => 14.2);
--
see 3.6 for declaration of type Vector
--
see 6.1 for declaration of Random
Tomorrow := ((Yesterday
with delta Day => 12)
with delta Month => April); --
see 3.8
Example where the
base expression is class-wide:
function Translate (P : Point'Class; X, Y : Real)
return Point'Class
is
(P
with delta X => P.X + X,
Y => P.Y + Y); --
see 3.9 for declaration of type Point
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe