CVS difference for ai12s/ai12-0125-3.txt

Differences between 1.6 and version 1.7
Log of other versions for file ai12s/ai12-0125-3.txt

--- ai12s/ai12-0125-3.txt	2016/04/26 05:00:36	1.6
+++ ai12s/ai12-0125-3.txt	2016/08/05 07:02:15	1.7
@@ -1,17 +1,21 @@
-!standard 5.2.1(0)                                 16-04-11  AI12-0125-3/03
+!standard 5.2.1(0)                                 16-08-04  AI12-0125-3/04
+!standard 2.2(9)
+!standard 3.3(21.1/3)
 !standard 4.1(2/3)
 !standard 8.6(9/4)
 !class Amendment 15-10-13
+!status Amendment 1-2012 16-08-04
+!status ARG Approved 10-0-2  16-06-12
 !status work item 15-10-13
 !status received 15-09-22
 !priority Low
 !difficulty Medium
-!subject Add @ as a shorthand for the LHS of an assignment
+!subject Add @ as a abbreviation for the LHS of an assignment
 
 !summary
 
 Define @, which can be used in the right-hand side of an assignment
-statement as a shorthand for the name of the left-hand side.
+statement as a abbreviation for the name of the left-hand side.
 
 !problem
 
@@ -21,7 +25,7 @@
 
    My_Package.My_Array(I).Field := My_Package.My_Array(I).Field + 1;
 
-Some sort of short-hand would be welcome, as it would ease both
+Some sort of shorthand would be welcome, as it would ease both
 readability and writability, while reducing the possibility of error,
 such as unintended multiple evaluations of expressions in the name, or
 mismatching array indices.
@@ -33,6 +37,9 @@
 
 !wording
 
+Add @ to the list in 2.2(9):
+   &    '    (    )    *    +    ,    –    .    /    :    ;    <    =    >    @    |
+
 Add after 3.3(21.1/3): [Editor's note: This is the list of items that are
 defined to be constant. Since that list is defined to be exclusive, we have
 to include target_name here.]
@@ -41,7 +48,7 @@
 
 [Editor's note: The "when used in the expression of the assignment" isn't
 strictly necessary, as that is the only place a target_name is allowed. But
-this is a forward reference and a causal reader might interpret this as
+this is a forward reference and a casual reader might interpret this as
 applying to the *variable_*name of the assignment -- which it does not.]
 
 Add target_name to the syntax of Name in 4.1(2/3).
@@ -53,23 +60,25 @@
 
 Add a new subclause:
 
-    5.2.1 Target name (@) shorthand
+    5.2.1 Target Name Symbols
 
     @, known as the *target name* of an assignment statement,
-    provides a shorthand to avoid repetition of potentially long
+    provides an abbreviation to avoid repetition of potentially long
     names in assignment statements.
 
     Syntax
 
-        Target_Name ::= @
+        target_name ::= @
 
     Name Resolution Rules
-
-    Redundant[If a target_name *T* occurs in an assignment_statement *A*, the
-    *variable_*name *V* of *A* is a complete context.] *T* is a constant view
-    of *V*, having the nominal subtype of *V*.
 
-    AARM The Proof: The complete context rule is formally given in 8.6.
+    Redundant[If a target_name occurs in an assignment_statement *A*, the
+    *variable_*name *V* of *A* is a complete context. The target name is a
+    constant view of *V*, having the nominal subtype of *V*.]
+
+    AARM The Proof: The complete context rule is formally given in 8.6. The
+    constant view rule is formally given in 3.3; the nominal subtype follows
+    from the equivalence given below in Static Semantics.
 
     Legality Rules
 
@@ -78,13 +87,14 @@
 
     Static Semantics
 
-    If a target_name with nominal subtype *S* appears in the expression of
-    an assignment statement *A*, then *A* is equivalent to a local anonymous
-    procedure having an in out parameter *P* of subtype *S*, with a
-    body being *S* with the *variable_*name being replaced by *P*, and
-    any target_names being replaced by the qualified expression
-    *S*'(*P*); followed by a call on the anonymous procedure with the
-    actual parameter being the *variable_*name of *S*.
+    @Redundant[The *variable_*name is evaluated only once.] In particular, if a
+    target_name with nominal subtype *S* appears in the expression of
+    an assignment statement *A*, then *A* is equivalent to a call on a local
+    anonymous procedure with the actual parameter being the *variable_*name of
+    *A*, where the local anonymous procedure has an in out parameter with
+    unique name *P* of subtype *S*, with a body being *A* with the
+    *variable_*name being replaced by *P*, and any target_names being replaced
+    by the qualified expression *S*'(*P*). 
 
     [Editor's note: We use a qualified expression here to ensure the
     replacement has the semantics of a constant view. I would have preferred
@@ -95,8 +105,7 @@
     that effect anyway, but it seems valuable to emphasize that to readers.]
 
     AARM Reason: This equivalence defines all of the Dynamic Semantics
-    for these assignment statements. We use the parameter to bind the
-    *variable_*name; it is evaluated only once.
+    for these assignment statements.
 
     AARM Discussion:
         For example, the expression
@@ -116,6 +125,19 @@
         placeholders.
     End AARM Discussion.
 
+    Examples
+
+    Board(1, 1) := @ + 1;  -- An abbreviation for Board(1, 1) := Board(1, 1) + 1;
+                           -- (Board is declared in 3.6.1)
+
+    Long_Ago : Date := Yesterday; -- See 3.8
+    Long_Ago := (Year  => @.Year - 1,
+                 Month => (if @.Month = January then January else Month_Name'Pred(@.Month)),
+                 Day   => (if @.Day = 1 then 28 else @.Day - 1));
+       -- A target_name can be used multiple times and as a prefix if needed.
+
+
+
 Add after 8.6(9/4):
 
    * The *variable_*name of an assignment_statement *A*, if the expression of
@@ -123,7 +145,7 @@
 
 !examples
   
-   X := @ + 1;  --  A shorthand for X := X + 1;
+   X := @ + 1;  --  An abbreviation for X := X + 1;
 
    A(I) := Integer'Max (@, 10);  --  Equivalent to:
    --  declare
@@ -135,6 +157,14 @@
    --     Anon (A(I));
    --  end;
 
+   -- If one has a function Clamp (Low, Value, High : S) return S that ensures
+   -- that Value is in the range Low .. High, then one could write:
+
+   Something_Long(1).Comp := Clamp (L, @ + X, U);
+
+   -- The preceeding two examples cannot be written using AI12-0125-2,
+   -- operations like :+ have limited applicability.
+
 The following example is some real code from the web log analyzer that makes
 usage reports for Ada-Auth.org and Archive.AdaIC.com (among others). The value
 of this proposal in reducing clutter is more evident in a real example. First,
@@ -181,7 +211,7 @@
         end if;
     end Record_Amount;
 
-Here is the same example using the @ shorthand (33 lines):
+Here is the same example using the @ abbreviation (33 lines):
 
     procedure Record_Amount (Data : in out Item_Data;
                              Month : in Month_Number;
@@ -296,7 +326,7 @@
 
 This proposal is better than AI12-0125-2, as
  (1) It is more flexible; it can be used in function calls other than operators
-     (as shown by the 'Max example above).
+     (as shown by the 'Max and Clamp examples above).
  (2) There is a positive indication that this notation is being used (the
      addition of an @ as opposed to deleting an '='); 
  (3) It doesn't (directly) depend on visibility of anything; it's always
@@ -317,7 +347,7 @@
  (1) The semantics is described in terms of an anonymous procedure.
  (2) The left-hand side of the assignment is treated as a complete context,
      meaning that in rare cases, introducing @ into an assignment (or using
-     :+) would make the assignment illegal.
+     :+) would make the assignment illegal if the LHS was ambiguous.
 
 These should be considered issues with solving the problem as opposed to
 negatives against a particular proposal.
@@ -327,9 +357,98 @@
      Obj:+1;     vs. Obj:=+1; -- The alternative AI12-0125-2
 
 Of course, writing without whitespace is discouraged in Ada, but these are
-legal expressions regardless of common practice. This problem could be
+legal expressions regardless of common practice. This problem could have been
 eliminated for this proposal by using more than one character for the target
-name (as the original proposal <<>> did).
+name (as the original proposal <<>> did), but that would also make it harder
+to write the abbreviation, reducing its utility.
+
+!corrigendum 2.2(9)
+
+@drepl
+& @ @  ' @ @  ( @ @  ) @ @  * @ @  + @ @  , @ @  @endash @ @  . @ @  / @ @  : @ @  ; @ @  < @ @  = @ @  @> @ @  |
+@dby
+& @ @  ' @ @  ( @ @  ) @ @  * @ @  + @ @  , @ @  @endash @ @  . @ @  / @ @  : @ @  ; @ @  < @ @  = @ @  @> @ @  @@ @ @  |
+
+!corrigendum 3.3(21.1/3)
+
+@dinsa
+@xbullet<the result of evaluating a @fa<qualified_expression>;>
+@dinst
+@xbullet<a @fa<target_name> of an @fa<assignment_statement> when used
+in the @fa<expression> of the assignment (see 5.2.1);>
+
+!corrigendum 4.1(2/3)
+
+@drepl
+@xcode<@fa<name>@fa< ::=>
+     @fa<direct_name> | @fa<explicit_dereference>
+   | @fa<indexed_component> | @fa<slice>
+   | @fa<selected_component> | @fa<attribute_reference>
+   | @fa<type_conversion> | @fa<function_call>
+   | @fa<character_literal> | @fa<qualified_expression>
+   | @fa<generalized_reference> | @fa<generalized_indexing>>
+@dby
+@xcode<@fa<name>@fa< ::=>
+     @fa<direct_name> | @fa<explicit_dereference>
+   | @fa<indexed_component> | @fa<slice>
+   | @fa<selected_component> | @fa<attribute_reference>
+   | @fa<type_conversion> | @fa<function_call>
+   | @fa<character_literal> | @fa<qualified_expression>
+   | @fa<generalized_reference> | @fa<generalized_indexing>
+   | @fa<target_name>>
+
+!corrigendum 5.2.1(0)
+
+@dinsc
+
+@@, known as the @i<target name> of an assignment statement,
+provides an abbreviation to avoid repetition of potentially long
+names in assignment statements.
+
+@s8<@i<Syntax>>
+
+@xindent<@fa<target_name>@fa< ::= >@@>
+
+@s8<@i<Name Resolution Rules>>
+
+If a @fa<target_name> occurs in an @fa<assignment_statement> @i<A>, the
+@i<variable_>@fa<name> @i<V> of @i<A> is a complete context. The target name is a
+constant view of @i<V>, having the nominal subtype of @i<V>.
+
+@s8<@i<Legality Rules>>
+
+A @fa<target_name> shall only appear in the @fa<expression> of an
+@fa<assignment_statement>.
+
+@s8<@i<Static Semantics>>
+
+The @i<variable_>@fa<name> is evaluated only once. In particular, if a
+@fa<target_name> with nominal subtype @i<S> appears in the @fa<expression> of
+an @fa<assignment_statement> @i<A>, then @i<A> is equivalent to a call on a local
+anonymous procedure with the actual parameter being the @i<variable_>@fa<name>
+of @i<A>, where the local anonymous procedure has an @b<in out> parameter with
+unique name @i<P> of subtype @i<S>, with a body being @i<A> with the
+@i<variable_>@fa<name> being replaced by @i<P>, and any @fa<target_name>s
+being replaced by the qualified expression @i<S>'(@i<P>). 
+
+@s8<@i<Examples>>
+
+@xcode<Board(1, 1) := @@ + 1;  -- @ft<@i<An abbreviation for Board(1, 1) := Board(1, 1) + 1;>>
+                       -- @ft<@i<(Board is declared in 3.6.1).>>>
+
+@xcode<Long_Ago : Date := Yesterday; -- @ft<@i<See 3.8.>>
+Long_Ago := (Year  =@> @@.Year - 1,
+             Month =@> (@b<if> @@.Month = January @b<then> January @b<else> Month_Name'Pred(@.Month)),
+             Day   =@> (@b<if> @@.Day = 1 @b<then> 28 @b<else> @@.Day - 1));
+   -- @ft<@i<A target_name can be used multiple times and as a prefix if needed.>>>
+
+!corrigendum 8.6(9/4)
+
+@dinsa
+@xbullet<The @i<selecting_>expression of a @fa<case_statement> or @fa<case_expression>.>
+@dinst
+@xbullet<The @i<variable_>@fa<name> of an @fa<assignment_statement> @i<A>, if
+the @fa<expression> of @i<A> contains one or more @fa<target_name>s.>
 
 !ASIS
 
@@ -2506,5 +2625,65 @@
 As I noted, I didn't go back to ideas proposed before Bennington (and there
 were many of those, too). It would have been fun to do so, but not a good use
 of time.
+
+****************************************************************
+
+From: Randy Brukardt
+Sent: Tuesday, August  2, 2016  12:09 AM
+
+I haven't actually worked on this AI yet (so there might be something else
+later), but I realized that I forgot something when I originally defined this
+AI. There is a list of "delimiters" (really single character lexical symbols)
+in 2.2(9). Clearly, we have to add '@' to that list. It should be added as the
+second-last item, as this list is in ASCII code order (and @ follows > and
+precedes | in that encoding).
+
+****************************************************************
+
+From: Jeff Cousins
+Sent: Tuesday, August  2, 2016  5:41 AM
+
+Well spotted.
+
+****************************************************************
+
+From: Randy Brukardt
+Sent: Friday, August  5, 2016  1:22 AM
+
+As I guessed, there would be more.
+
+The otherwise brilliant author of this AI (that would be me) forgot to provide
+examples for this new subclause. It seems rather important to do so, as the
+formal definition is rather inscrutable.
+
+Of course, RM examples have to be based on previous declarations in the RM, so
+all of the existing examples in the AI are no good. I propose that we use the
+following:
+
+Examples
+
+    Board(1, 1) := @ + 1;  -- An abbreviation for Board(1, 1) := Board(1, 1) + 1;
+                           -- (Board is declared in 3.6.1).
+
+    Long_Ago : Date := Yesterday; -- See 3.8
+    Long_Ago := (Year  => @.Year - 1,
+                 Month => (if @.Month = January then January else Month_Name'Pred(@.Month)),
+                 Day   => (if @.Day = 1 then 28 else @.Day - 1));
+       -- A target_name can be used multiple times and as a prefix if needed.
+
+If you have an improvement, please suggest it (there's not many exciting types
+declared in chapter 3 or 4).
+
+[Note: Month_Name is never actually defined in the RM, 4.3.1 uses it however
+and uses the full month names so I followed suit here. I suppose Jeff will ask
+me to add Month_Name to the examples in 3.5.1.]
+
+---
+
+In other news, I marked the entire Name Resolution Paragraph as redundant,
+given that the first sentence is formally defined in 8.6 (that was already in
+the AI), the first half of the second sentence is given in 3.3, and the
+second half of the second sentence is given in the Static Semantics
+equivalence.
 
 ****************************************************************

Questions? Ask the ACAA Technical Agent