CVS difference for ai05s/ai05-0139-2.txt

Differences between 1.5 and version 1.6
Log of other versions for file ai05s/ai05-0139-2.txt

--- ai05s/ai05-0139-2.txt	2010/02/23 07:31:06	1.5
+++ ai05s/ai05-0139-2.txt	2010/05/20 02:56:40	1.6
@@ -1,4 +1,4 @@
-!standard 5.5                                       10-02-11  AI05-0139-2/04
+!standard 5.5                                       10-05-18  AI05-0139-2/05
 !class Amendment 09-02-13
 !status work item 09-02-13
 !status received 09-01-19
@@ -36,7 +36,7 @@
 
 !proposal
 
-Define a "magic" interface, a new operator, a "magic" generic unit,
+Define a "magic" interface, a "magic" generic unit,
 and some additional "aspects" for the aspect_specification, all of
 which are linked to some appropriate syntactic sugar for accessors,
 containers, and iterators:
@@ -129,17 +129,26 @@
 
 2) SUPPORT FOR CONTAINER INDEXING
 
-We now take this one step further by allowing the definition of a new
-operator, "()", which allows the elimination of the function name in
-uses like that above, simplifying the notation to simply
-"Tab("Banana")". This works as follows:
+We now take this one step further by allowing the definition of two new
+aspects, Constant_Indexing and Variable_Indexing, which allow the
+elimination of the function name in uses like that above, simplifying
+the notation to simply "Tab("Banana")". This works as follows:
 
     package Whatever is
        ... as above
 
-       function "()"(Tab : access T_Table; Key : String) return Ref_T;
+       type T_Table is tagged limited private
+         with Variable_Indexing => Element;
+              Constant_Indexing => Element_RO;
 
-       ...
+       type Ref_Const_T(Data : access constant T) is
+         new Ada.Finalization.Limited_Controlled
+           and Ada.References.Reference with ...
+
+       function Element_RO(Tab : access constant T_Table; Key : String)
+         return Ref_Const_T;
+
+       ... as above
     end Whatever;
 
 Now the body of Do_Something can be simply:
@@ -160,40 +169,33 @@
 same way as an array is indexed, with the key (or potentially
 various different key types) being arbitrary.
 
-The basic rule with "()" is that it must be suitable for prefix
-notation, meaning that it is either a primitive operation or a
-class-wide operation of some tagged type (via its first parameter), and
-if class-wide, is declared immediately within a package where some
-tagged type covered by the class-wide type is immediately declared. It
+The basic rule with the Variable_Indexing and Constant_Indexing
+aspects is that all subprograms with the given name declared
+immediately within the same declaration list as the type,
+must be suitable for calling using prefix notation, given
+a variable or constant (respectively) of the associated type,
+meaning that it is either a primitive operation or a
+class-wide operation of the tagged type (via its first parameter). It
 must have at least two parameters. There seems no particular reason it
-couldn't have more than two parameters. There are no predefined "()"
-operators, though one could imagine that all array types have such
-operators, if it helps in understanding the model.
-
-One relatively important rule for "()" is that one can define two
-operators, one that requires the controlling operand to be a variable,
-and one that allows it to be a constant, and overload resolution will
-resolve to the one that requires a variable if the actual is a variable,
-and otherwise it will resolve to the one that allows a constant. This
-rule is important so that the same notation, such as "Container(Key)",
-can be used when Container is a constant as when it is a variable, and
-the variableness of the result can be determined by the variableness of
-the Container.
-
-Hence, we would more likely in a package such as the one used in
-the above example, define an additional reference type:
-
-   type Ref_Const_T(Data : access constant T) is
-     new Ada.Finalization.Limited_Controlled
-       and Ada.References.Reference with ...
-
-and an additional "()" operator:
-
-   function "()"(Tab : access constant Table; Key : String) return Ref_Const_T;
-
-With these two additional declarations, we can now use the "Tab(Key)"
-notation whether "Tab" is a constant or a variable, and the appropriate
-overloading of "()" will be invoked.
+couldn't have more than two parameters. There are no predefined _Indexing
+aspects, though one could imagine that all array types have such
+aspects, if it helps in understanding the model.
+
+If only the Variable_Indexing aspect is defined, then indexing
+may only be applied to variables.  If only the Constant_Indexing
+aspect is defined then indexing may be applied to a variable or
+a constant, but not in a context that requires the result to be
+a variable.  If both aspects are defined, then the Variable_Indexing
+aspect is used when the indexing is used in a context that requires
+a variable, or in an object renaming where the prefix is a variable;
+the Constant_Indexing aspect is used otherwise.
+
+With these two additional aspects defined, we can now use the "Tab(Key)"
+notation on both the left-hand-side of an assignment (on variables)
+and on the right-hand-side (on variables or constants).
+Note that we try to use Constant_Indexing wherever it is legal
+since it presumably has lower overhead, particularly if indexing
+into a "persistent" constainer.
 
 3) SUPPORT FOR ITERATORS
 
@@ -223,7 +225,7 @@
    begin
       while Cursor /= No_Element loop
          Container(Cursor) := Container(Cursor) + 1;
-           -- This presumes an appropriate "()" operator
+           -- This presumes an appropriate _Indexing aspect
            -- is defined.
 
          Cursor := Next(_iter, Cursor);
@@ -238,18 +240,18 @@
        No_Element : in Cursor;
    package Ada.Iterator_Interfaces is
 
-       type Basic_Iterator is limited interface;
-       function First (Object : Basic_Iterator) return Cursor;
-       function Next (Object : Basic_Iterator; Position : Cursor) return Cursor;
+       type Forward_Iterator is limited interface;
+       function First (Object : Forward_Iterator) return Cursor;
+       function Next (Object : Forward_Iterator; Position : Cursor) return Cursor;
 
-       type Reversible_Iterator is limited interface and Basic_Iterator;
+       type Reversible_Iterator is limited interface and Forward_Iterator;
        function Last (Object : Reversible_Iterator) return Cursor;
        function Previous (Object : Reversible_Iterator; Position : Cursor) return Cursor;
 
    end Ada.Iterator_Interfaces;
 
 By instantiating this package with a given cursor type, and then
-deriving one or more type(s) from the Basic_Iterator and/or
+deriving one or more type(s) from the Forward_Iterator and/or
 Reversible_Iterator interfaces, this first iterator syntax is enabled for
 the given iterator type(s). See above for an example.
 
@@ -259,7 +261,7 @@
 object parameter to the Next and Previous functions (which is necessary
 to make them part of the interface).
 
-The interface Basic_Iterator defines a user-defined iterator for the
+The interface Forward_Iterator defines a user-defined iterator for the
 forward direction; the interface Reversible_Iterator defines a
 user-defined iterator for both the forward and reverse direction.
 Descendants of Reversible_Iterator can be used in loops with the
@@ -283,14 +285,14 @@
 b) The second syntax is intended for iterating directly over the elements
 of a container or an array:
 
-   for Element of Container loop
-       Element := Element + 1;
+   for Elem of Container loop
+       Elem := Elem + 1;
    end loop;
 
 or
 
-   for Element of Arr loop
-       Element := Element + 1;
+   for Elem of Arr loop
+       Elem := Elem + 1;
    end loop;
 
 This second syntax is more convenient, but less flexible, in that there
@@ -308,10 +310,10 @@
    begin
       while _Cursor /= No_Element loop
         declare
-          Element : Container_Type'Iterator_Element renames Container(_Cursor);
-            -- This requires an appropriate "()" operator be defined
+          Elem : Container_Type'Iterator_Element renames Container(_Cursor);
+            -- This requires an appropriate _Indexing aspect being defined
         begin
-          Element := Element + 1;
+          Elem := Elem + 1;
 
           _Cursor := Next(_Iter, _Cursor);
         end;
@@ -325,19 +327,23 @@
     package Iterators is new Ada.Iterator_Interfaces(Cursor_Type, No_Element);
     type Container is ...
        with
-         Default_Iterator => Iterate,
-         Iterator_Element => Element;
+         Variable_Indexing => Element,
+         Constant_Indexing => Element_RO,
+         Default_Iterator  => Iterate,
+         Iterator_Element  => Element;
 
-    type Element_Ref(E : access Element) is limited
+    type Element_Ref(E : access Element_Type) is limited
       new Ada.References.Reference with private;
-    type Element_CRef(E : access constant Element) is limited
+    type Element_CRef(E : access constant Element_Type) is limited
       new Ada.References.Reference with private;
 
     type Iterator_Type is new Iterators.Reversible_Iterator with ...
     function Iterate(Con : Container) return Iterator_Type;
 
-    function "()"(Con : access Container; Cur : Cursor_Type) return Element_Ref;
-    function "()"(Con : access constant Container; Cur : Cursor_Type) return Element_CRef;
+    function Element(Con : access Container; Cur : Cursor_Type)
+      return Element_Ref;
+    function Element_RO(Con : access constant Container; Cur : Cursor_Type)
+      return Element_CRef;
     ...
 
 
@@ -348,15 +354,15 @@
    defining_identifier [: subtype_indication] OF container_expression
 
 The first requires an expression returning an object of a type
-descended from Basic_Iterator, or Reversible_Iterator if REVERSE appears.
+descended from Forward_Iterator, or Reversible_Iterator if REVERSE appears.
 The defining_identifier is of the corresponding Cursor type, and can
 be used to index into the container.
 
 The second requires an expression returning an array, or an object
 of a type which has aspects Default_Iterator and Iterator_Element
 specified. The subtype_indication is optional, since the Iterator_Element
-aspect of the container type determines the Element type. Similarly for an
-array, the Element type is simply the array component type. One purpose of
+aspect of the container type determines the element type. Similarly for an
+array, the element type is simply the array component type. One purpose of
 the subtype_indication might be to tighten the requirements on the
 elements of the container/array, acting essentially as an assertion
 about the values stored in the container/array at the time of
@@ -372,7 +378,7 @@
    for C in V.Iterate loop
       V(C) := V(C) + 1;
         -- Note that this presumes appropriate
-        -- "()" operators have been defined.
+        -- _Indexing aspects have been defined.
    end loop;
 
 Some examples of the second iterator would be:
@@ -393,8 +399,10 @@
    ...
    for X of Vec loop
           -- X renames Vec(<cursor>) where <cursor> in Default_Iterator(Vec).
-          --    and Vec(<cursor>) is equiv to "()"(Vec, <cursor>).Discrim.all.
-          -- X is a variable if Vec is a variable.
+          --    If Vec is a variable, Vec(<cursor>) is equiv to
+          --       Vec'Variable_Indexing(Vec, <cursor>).Discrim.all
+          --    and if Vec is a constant, is equiv to
+          --       Vec'Constant_Indexing(Vec, <cursor>).Discrim.all
 
        X := X + 1;
    end loop;
@@ -478,7 +486,7 @@
 It would be nice for an iterator implementation to be able to prevent the
 creation of iterator objects not associated with a loop. For instance, given
 the implementation of the example below:
-    My_Iter : Some_Instance.Basic_Iterator'Class := My_List.Iterator;
+    My_Iter : Some_Instance.Forward_Iterator'Class := My_List.Iterator;
 would have the effect setting tampering on My_List and keeping it set until
 the object is destroyed (potentially a long time in the future). But this
 is not the natural thing to do -- it requires a lot more typing than the intended
@@ -3368,3 +3376,15 @@
 white paper to better explain how these generics work.
 
 ****************************************************************
+
+From: Tucker Taft
+Sent: Tuesday, May 18, 2010  8:53 PM
+
+Here is an update to AI05-0139-2. [This is version /05 of the AI - Editor.]
+This does *not* have wording yet.  It just fixes the !proposal part to match the
+changes specified in the minutes.  I will work on the wording for the actual ARG
+meeting.  The !proposal section might be worth reviewing in the upcoming ARG
+subgroup phone call.
+
+****************************************************************
+

Questions? Ask the ACAA Technical Agent