!standard 3.5(31/2) 14-08-11 AI12-0125-1/01 !class Amendment 14-08-11 !status work item 14-08-11 !status received 14-08-08 !priority Low !difficulty Easy !subject Add Object'Succ and 'Pred !summary Define Succ and Pred procedures with an object prefix. !problem It would be useful to have a shorthand for the common case of an assignment that updates its target object with an increment or decrement of the target. That is, we would like a shorthand for: X := X + 1; or X := My_Subtype'Succ(X); such that the target name does not need to be repeated. The motivation for such a shorthand is to aid readability, because often such assignments involve an object with a longish identifier (as Ada tends to encourage) or a complex compound name, and repeating the full name in the assignment expression is unwieldy and tends to make the statement too heavy and hence less readable. That's especially true when the Succ or Pred attributes are involved because an additional, often lengthy, subtype name is involved as well. !proposal (See Wording.) !wording Add somewhere in 3.5: (Note that the attribute list doesn't appear to be in any obvious order, so perhaps these are best added at the tail end.) For a prefix X that denotes a variable of a scalar type: X'Succ Denotes a parameterless procedure that updates X with the result of S'Succ(X), where S is the nominal subtype of X. X'Pred Denotes a parameterless procedure that updates X with the result of S'Pred(X), where S is the nominal subtype of X. [Alternatively, we could describe the entire procedure: procedure X'Succ is *Obj* : *S* renames X; begin *Obj* := *S*'Succ(*Obj*); end X'Succ;] !discussion Note that in these forms, the prefix name is evaluated precisely once (as in the rename in the semantic description above), so this is not completely equivalent to X := S'Succ(X) if the evaluation of X has any side-effects. These aspects are similar to the magic Inc and Dec subprograms in Modula. Indeed, the author originally thought that the purpose of the Succ and Pred attributes in Ada was the same as the Modula ones; it was a surprise that they don't work that way and are actually overly wordy. (The author hardly ever uses these attributes; this form would make them much more useful.) These attributes (unfortuately) do not chain: since these are procedures, X'Succ'Succ is illegal. It has to be written as X'Succ; X'Succ. An alternative proposed in the past would be to allow an optional argument to these attributes, which would provide a repeat factor. In this option, X'Succ(2) would be the same as X'Succ; X'Succ without the repeat evaluation. The definition would be something like: procedure X'Succ (Count : *universal_integer* := 1) is *Obj* : *S* renames X; begin for I in 1 .. Count loop *Obj* := *S*'Succ(*Obj*); end loop; end X'Succ; (preferably with a permission/requirement to do the read and write only once, even for a volatile X). We did not propose this as it would be prone to misuse when the object is of an integer type. In particular, someone confusing the subtype and object forms might write: X'Succ(X) when they really meant just X'Succ and it would be legal and they'd get a very surprising result (X*2) from the first form. We could prevent this problem by requiring the expression to be a static expression (X necessarily having to be a variable) but that would also restrict the usefulness of the construct. This issue was originally raised in AI05-0187-1. Most of the discussion on that AI centered on a ":=+" shorthand. That proved to be problematical when user-defined operations were involved; when the target and operators are overloaded in some way, X := X + 1 and X :=+ 1 could resolve to different operations. That's not a problem for Succ and Pred, which are only predefined. !ASIS No ASIS impact. !ACATS test An ACATS C-Test is needed to verify that the attributes are implemented as specified. !appendix ****************************************************************