Ada Programming/Attributes/'Update

Description
The  attribute creates a copy of an array or record value with one or more modified components. The syntax is: where  is the name of an array or record object, the association list in parentheses does not contain an   choice and the box symbol   may not appear in any expression. The effect is to yield a copy of the array or record value which is unchanged apart from the components mentioned in the association list, which are changed to the indicated value. The original value of the array or record value is not affected. For example: yields a value for  of 1,10,20,20,5 with   begin unmodified. Similarly: yields a value for  of (A => 1, B => 20, C => 3), with   being unmodifed. Note that the value of the attribute reference is computed completely before it is used. This means that if you write: then the value of  is not modified if   raises an exception, unlike the effect of a series of direct assignments to elements of. In general this requires that two extra complete copies of the object are required, which should be kept in mind when considering efficiency.

The  attribute cannot be applied to prefixes of a limited type, and cannot reference discriminants in the case of a record type. The accessibility level of an Update attribute result object is defined as for an aggregate.

In the record case, no component can be mentioned more than once. In the array case, two overlapping ranges can appear in the association list, in which case the modifications are processed left to right.

Multi-dimensional arrays can be modified, as shown by this example: which changes element (1,2) to 20 and (3,4) to 30.