4.3.4 Delta Aggregates
{
AI12-0127-1}
{
AI12-0324-1}
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
Legality Rules
Ramification: The
base_expression
of a
record_delta_aggregate
may be of a limited type (for example a record with limited components),
as it is not restricted. A rule in
4.3.1
ensures that we do not assign to a limited component. We do not allow
any part of an
array_delta_aggregate
to be of a limited type, even the
base_expression,
as this is a useless construct (you would not be able to update anything
because the components necessarily are also limited except in pathological
cases).
Dynamic Semantics
Ramification: This is the same anonymous
object as described in
7.6, “
Assignment
and Finalization”; in particular, it might be required to be
built in place.
For a specific tagged type, any extension components
that the actual object underlying the
base_expression
might have are not used to initialize the anonymous object, which is
critical if the aggregate is required to be built-in-place.
To be honest: The anonymous object associated
with the evaluation of a
delta_aggregate
begins its life as a variable, not a constant (
3.3
notwithstanding). This must be the case because the object is initialized
and then subsequently modified. After evaluation of the
delta_aggregate
is complete, the object is a constant object. This is similar to the
way that an extended return statement can provide a variable view of
an object that will eventually be a constant object after the function
returns its result.
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.
Reason: Unlike other
aggregates,
an
array_delta_aggregate
is evaluated in the order that it is written. This is necessary to get
deterministic behavior, as (unlike other
aggregates,
including
record_delta_aggregates)
there is no requirement that the specified components be distinct. As
such, the order requirement ensures that every
array_delta_aggregate
has a well-defined result, even if the same component is specified multiple
times.
Examples
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);
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
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
Extensions to Ada 2012
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe