CVS difference for ai12s/ai12-0312-1.txt

Differences between 1.10 and version 1.11
Log of other versions for file ai12s/ai12-0312-1.txt

--- ai12s/ai12-0312-1.txt	2019/10/01 02:03:04	1.10
+++ ai12s/ai12-0312-1.txt	2019/10/02 00:14:31	1.11
@@ -1,4 +1,4 @@
-!standard 5.5.2(2/3)                                  19-09-27  AI12-0312-1/05
+!standard 5.5.2(2/3)                                  19-10-01  AI12-0312-1/06
 !class presentation 19-02-07
 !status work item 19-02-07
 !status received 19-02-07
@@ -33,7 +33,7 @@
 and googling famous people named Casey produces about an even mix of the sexes.
 Chris produced mostly male for example, and Pat was also heavily male oriented]
 
-Append after 4.2.1(10/5):
+Append after 4.2.1(9.d/5):
 
 Examples
 
@@ -61,7 +61,7 @@
                  when 'C' => 100,
                  when 'D' => 500,
                  when 'M' => 1000,
-                 when others => 0)) [<= Author's note: This is needed because S is of type String, even though precondition makes this impossible?]
+                 when others => raise Program_Error with "Impossible")) [<= Author's note: This is needed because S is of type String, even though precondition makes this impossible?]
       begin
         [for I in R'Range =>
           (if I < R'Last and then R(I) < R(I + 1) then -1 else 1) * R(I))]
@@ -74,13 +74,15 @@
 
 Empty_Matrix : constant Matrix := []; -- A matrix without elements
 
+Delete paragraph 4.3.5(86/5-87-5). [Already show example of empty container aggregate]
+
 Delete paragraph 4.3.5(97/5). [Alternate form example shown above]
 
 Delete paragraphs 4.3.5(99/5 - 100/5).  [Already show example of empty container aggregate]
 
 Delete paragraphs 4.3.5(105/5 - 106/5). [Example is not that different from others]
 
-Append after 4.5.7(21/3):
+Append after 4.5.7(22.a/5):
 
 Examples
    Put_Line ("Casey is " & (if Casey.Sex = M then "Male" else "Female")); -- See 3.10.1
@@ -117,6 +119,23 @@
       begin
         Acc.Sum / Real(Acc.Count));
 
+    A parallel reduction expression used to determine the set of prime
+    numbers within a range of values:
+
+   package Integer_Sets is new
+     Ada.Containers.Ordered_Sets (Element_Type => Integer);
+
+    function Is_Prime (Value : Integer) return Boolean is
+    begin
+       ...
+    end Is_Prime;
+
+    All_Primes : constant Integer_Sets.Set :=
+       [parallel for I in 1 .. 1_000_000
+          when Is_Prime (I) => I]'Reduce (Integer_Sets.Include,
+                                          [],
+                                          Integer_Sets.Union);
+
 Modify 5.5(22/5):
 "Example{s} of [a] parallel loop{s}: "
 
@@ -148,19 +167,19 @@
             ", Max=" & Partial_Max'Reduce(Natural'Max, 0));
 end;
 
-Append after 6.1.1(41/3):
+Append after 6.1.1(42/3):
 
 6 For an example of the use of these aspects and attributes, see the Streams
 Subsystem definitions in 13.13.1.
 
-Append after 6.1.2(42/5):
+Append after 6.1.2(50.b/5):
 
 NOTES
 
 For an example of the use of these aspects, see the Vector container definition
 in A.18.2.
 
-Append after 7.3.2(24/3):
+Append after 7.3.2(24.a/3):
 
 Examples
 
@@ -209,12 +228,8 @@
 
    end Work_Orders;
 
-For another example of the use of the Type_Invariant aspect, see the Vector container definition
-in A.18.2.
-
+Append after 7.3.3(9.a/5):
 
-Append after 7.3.3(9/5):
-
 NOTES
 
 For an example of the use of this aspect, see the Vector container definition in
@@ -225,101 +240,6 @@
 For an example of a raise expression, see the Streams Subsytem definitions in
 13.13.1.
 
-Modify A.18.2(8/5):
-
-type Vector is tagged private
-      with Constant_Indexing => Constant_Reference,
-           Variable_Indexing => Reference,
-           Default_Iterator  => Iterate,
-           Iterator_Element  => Element_Type,
-           Iterator_View     => Stable.Vector,
-           Aggregate         => (Empty          => Empty,
-                                 Add_Unnamed    => Append_One,
-                                 New_Indexed    => New_Vector,
-                                 Assign_Indexed => Replace_Element),
-           Stable_Properties => (Length, Capacity,
-                                 Tampering_With_Cursors_Prohibited,
-                                 Tampering_With_Elements_Prohibited),
-           Default_Initial_Condition =>
-              Length (Vector) = 0 and then
-              (not Tampering_With_Cursors_Prohibited (Vector)) and then
-              (not Tampering_With_Elements_Prohibited (Vector)){,
-           Type_Invariant => Length (Vector) <= Capacity (Vector)};
-
-Modify A.18.5(3/5):
-
-type Map is tagged private
-      with Constant_Indexing => Constant_Reference,
-           Variable_Indexing => Reference,
-           Default_Iterator  => Iterate,
-           Iterator_Element  => Element_Type,
-           Iterator_View     => Stable.Map,
-           Aggregate         => (Empty     => Empty,
-                                 Add_Named => Insert),
-           Stable_Properties => (Length,
-                                 Tampering_With_Cursors_Prohibited,
-                                 Tampering_With_Elements_Prohibited),
-           Default_Initial_Condition =>
-              Length (Map) = 0 and then
-              (not Tampering_With_Cursors_Prohibited (Map)) and then
-              (not Tampering_With_Elements_Prohibited (Map)){,
-           Length (Map) <= Capacity (Map)};
-   pragma Preelaborable_Initialization(Map);
-
-Modify A.18.6(16.7/5):
- procedure Assign (Target : in out Map; Source : in Map)
-      with Pre  => (if Tampering_With_Cursors_Prohibited (Target)
-                    then raise Program_Error),
-           Post => Length (Source) = Length (Target) [and then
-                   Capacity (Target) >= Length (Source)];
-
-[Author's note: This is a bug in the RM. Ordered maps do not have a Capacity function!]
-
-Modify A.18.8(3/5):
-type Set is tagged private
-      with Constant_Indexing => Constant_Reference,
-           Default_Iterator  => Iterate,
-           Iterator_Element  => Element_Type,
-           Iterator_View     => Stable.Set,
-           Aggregate         => (Empty       => Empty,
-                                 Add_Unnamed => Include),
-           Stable_Properties => (Length,
-                                 Tampering_With_Cursors_Prohibited),
-           Default_Initial_Condition =>
-              Length (Set) = 0 and then
-              (not Tampering_With_Cursors_Prohibited (Set)){,
-           Length (Set) <= Capacity (Set)};
-   pragma Preelaborable_Initialization(Set);
-
-Modify A.18.20(5/3):
-  type List (Capacity : Count_Type) is tagged private{,
-     with Type_Invariant => Length (List) <= List.Capacity};
-
-[Author's question: I presume that we only need to describe type invariants
-for bounded containers where the unbounded forms do not already have such a
-type invariant? Also, presuming that in unbounded forms it's OK to use
-non- object prefix form (for consistency, and not need to redefine to
-use prefix form for bounded containers even though that is required
-because Capacity is a discriminant, not a primitive operation?
-Otherwise, we'd need to explicitly show the type invariant for all
-bounded containers, and describe that the non-prefix notation form
-doesn't exist, which seems like unnecessary detail.]
-
-Modify A.18.22(5/3):
-
-   type Map (Capacity : Count_Type) is tagged private{,
-     with Type_Invariant => Length (Map) <= Map.Capacity};
-
-Modify A.18.24(5/3):
-
-type Set (Capacity : Count_Type) is tagged private{,
-     with Type_Invariant => Length (Set) <= Set.Capacity};
-
-Modify A.18.25(5/3):
-
-type Tree (Capacity : Count_Type) is tagged private{,
-     with Type_Invariant => Length (Tree) <= Tree.Capacity};
-
 Modify B.3(78/3):
 --Calling the C Library Function{s} strcpy{, and printf}
 with Interfaces.C;
@@ -1182,8 +1102,8 @@
 From: Brad Moore
 Sent: Saturday, September 28, 2019  6:20 PM
 
-In the minutes from last meeting, I was asked to see if I could simplify 
-the Reduction Expression example for 4.5.10 (53/5), possibly by using a set 
+In the minutes from last meeting, I was asked to see if I could simplify
+the Reduction Expression example for 4.5.10 (53/5), possibly by using a set
 container.
 
 The example currently in the AI is;
@@ -1213,9 +1133,9 @@
 
 However, I do think the example can be simplified, without using containers.
 
-We can eliminate the need for a separate combiner function by having the 
+We can eliminate the need for a separate combiner function by having the
 map/reduce part of the value_sequence produce an Accumulator object rather
-than a real value as an input to the reduction. The count part of the 
+than a real value as an input to the reduction. The count part of the
 accumulator is 1, which gets tallied up by the reducer.
 
 If we do that, then the example becomes;
@@ -1236,7 +1156,7 @@
       begin
         Acc.Sum / Real(Acc.Count));
 
-It this enough of a simplification for this example? I looks pretty simple to 
+It this enough of a simplification for this example? I looks pretty simple to
 me.
 
 ****************************************************************
@@ -1246,7 +1166,7 @@
 
 > It this enough of a simplification for this example? I looks pretty simple to me.
 
-Much better; I'd rather call the function Reducer (or something else) to avoid the 
+Much better; I'd rather call the function Reducer (or something else) to avoid the
 "'Reduce(Reduce"
 
 ****************************************************************
@@ -1263,19 +1183,19 @@
 
 I agree with both comments, and ultimately went with Eds suggestion.
 
-I am now wondering though, whether we need the combiner field for parallel 
+I am now wondering though, whether we need the combiner field for parallel
 reduction at all?
 
-The combiner field (the third parameter to a reduction attribute is only 
-needed for parallel reductions, when the types of the parameters to the 
-reducer function are different types. For non-parallel reduction, there is no 
+The combiner field (the third parameter to a reduction attribute is only
+needed for parallel reductions, when the types of the parameters to the
+reducer function are different types. For non-parallel reduction, there is no
 need to combine results from different threads of execution.
 
-This example shows that it can be possible to simplify the expression to a 
-form that doesn't need the combiner, by using the map/reduce part of the value 
+This example shows that it can be possible to simplify the expression to a
+form that doesn't need the combiner, by using the map/reduce part of the value
 sequence to make both parameters of the reduction the same type.
 
-Another motivating example that was used for justifying the combiner is a 
+Another motivating example that was used for justifying the combiner is a
 concatenation example.
 
 Consider:
@@ -1294,8 +1214,8 @@
    [parallel for Letter in 'A' .. 'Z' => String'(1 => Letter)]'Reduce("&", "");
 
 
-It is at least worthwhile to consider if eliminating the combiner from the syntax would 
-"guide" programmers to  write simpler, more readable code, which is one of the features 
+It is at least worthwhile to consider if eliminating the combiner from the syntax would
+"guide" programmers to  write simpler, more readable code, which is one of the features
 I generally like about Ada.
 
 ****************************************************************
@@ -1304,39 +1224,39 @@
 Sent: Monday, September 30, 2019  8:24 PM
 
 ...
-> I am now wondering though, whether we need the combiner field for 
+> I am now wondering though, whether we need the combiner field for
 > parallel reduction at all?
 ...
-> This example shows that it can be possible to simplify the expression 
-> to a form that doesn't need the combiner, by using the map/reduce part 
-> of the value sequence to make both parameters of the reduction the 
+> This example shows that it can be possible to simplify the expression
+> to a form that doesn't need the combiner, by using the map/reduce part
+> of the value sequence to make both parameters of the reduction the
 > same type.
 
-Didn't we consider that when we designed this feature? Didn't we decide that 
-the performance impact of eliminating the combiner would be unacceptable? 
-After all, the only reason for parallelizing something is to improve the 
-performance, and if doing that requires making a lot of expensive copies 
-then that doesn't make much sense. I'm certain that we discussed this at 
-least once and probably more than once. I'd suggest going back through 
-the mail/minutes on this topic (AI12-0242-1 & AI12-0262-1) to see what we 
-discussed about it in the past (rather than reopening a discussion that we've 
+Didn't we consider that when we designed this feature? Didn't we decide that
+the performance impact of eliminating the combiner would be unacceptable?
+After all, the only reason for parallelizing something is to improve the
+performance, and if doing that requires making a lot of expensive copies
+then that doesn't make much sense. I'm certain that we discussed this at
+least once and probably more than once. I'd suggest going back through
+the mail/minutes on this topic (AI12-0242-1 & AI12-0262-1) to see what we
+discussed about it in the past (rather than reopening a discussion that we've
 had in the past).
 
-IMHO, this feature is complex enough without forcing people to jump through 
+IMHO, this feature is complex enough without forcing people to jump through
 hoops to figure out how to encode the parameters as both the same type. Just
 because something is *possible* doesn't mean that we ought to make the *only*
-way. And I'm pretty sure we had examples that didn't work well without 
-allowing the parameters to be of different types (which then requires a 
+way. And I'm pretty sure we had examples that didn't work well without
+allowing the parameters to be of different types (which then requires a
 combiner).
 
->It is at least worthwhile to consider if eliminating the combiner from 
->the syntax would "guide" programmers to write simpler, more readable 
+>It is at least worthwhile to consider if eliminating the combiner from
+>the syntax would "guide" programmers to write simpler, more readable
 >code, which is one of the features I generally like about Ada.
 
-There's no reduction code that will ever qualify as "simpler" or "readable". 
-The idea itself is a brain-bender for most - I'd guess that most of us will 
-have to write out the expansion of any such expression to figure out what's 
-going on. (There are some of course who find such things "natural", but 
+There's no reduction code that will ever qualify as "simpler" or "readable".
+The idea itself is a brain-bender for most - I'd guess that most of us will
+have to write out the expansion of any such expression to figure out what's
+going on. (There are some of course who find such things "natural", but
 they're weird. ;-)
 
 ****************************************************************
@@ -1344,23 +1264,23 @@
 From: Brad Moore
 Sent: Sunday, September 29, 2019  7:58 PM
 
-Here is my homework for the upcoming ARG meeting, which addresses all 
-comments captured in the Warsaw meeting. [This is version /05 of the AI - 
+Here is my homework for the upcoming ARG meeting, which addresses all
+comments captured in the Warsaw meeting. [This is version /05 of the AI -
 Editor.]
 
-Also, I do have recollection of having addressed Jeff's comments a long time 
+Also, I do have recollection of having addressed Jeff's comments a long time
 ago, so I was curious to find out why his early comments were not incorporated
 into the version we were looking at in Warsaw.
 
-It turns out that on March 7th, 2019, I sent out an update which addressed 
-Jeff's comments. However, that version of the AI did not seem to properly 
-make it into the system. 
+It turns out that on March 7th, 2019, I sent out an update which addressed
+Jeff's comments. However, that version of the AI did not seem to properly
+make it into the system.
 
-There is a version 1.4 of the AI, which corresponds to Mar 8th, which seems 
-like it should be the version that corresponds to my sent email, but it 
+There is a version 1.4 of the AI, which corresponds to Mar 8th, which seems
+like it should be the version that corresponds to my sent email, but it
 doesn't have the changes that I sent out.
 
-Anyway, I hope I now have addressed Jeff's comments in this new version of 
+Anyway, I hope I now have addressed Jeff's comments in this new version of
 the AI.
 
 ****************************************************************
@@ -1389,7 +1309,7 @@
 
 Some of the paragraph numbers seem odd places to give the examples:
 
-6.1.1(41/3) (actually now up to 41/5) is in Implementation Permissions, 
+6.1.1(41/3) (actually now up to 41/5) is in Implementation Permissions,
 6.1.2(42/5) is in the middle of Legality Rules.
 
 ****************************************************************
@@ -1398,13 +1318,13 @@
 Sent: Monday, September 30, 2019  4:27 PM
 
 The paragraph numbers in "new" clauses, like 6.1.2, change every time there is
-a change to those clauses, so they have to be rechecked with every version. 
-Also, we have a meta-rule allowing paragraph numbers of non-normative material 
-to change, so if there are additions near the end of a clause, the paragraph 
+a change to those clauses, so they have to be rechecked with every version.
+Also, we have a meta-rule allowing paragraph numbers of non-normative material
+to change, so if there are additions near the end of a clause, the paragraph
 numbers of examples may change.
- 
-Which is a long-winded way of saying that Brad probably had the right paragraph 
-numbers when he wrote the AI, but they've probably changed since. It would be 
+
+Which is a long-winded way of saying that Brad probably had the right paragraph
+numbers when he wrote the AI, but they've probably changed since. It would be
 hard to keep up.
 
 ****************************************************************
@@ -1444,21 +1364,21 @@
 This would be a normative change, so it doesn't belong in an AI about examples.
 If we're going to do this, it will have to be in some other AI.
 
-I presume that you added this change based on Tucker's comment from the 
+I presume that you added this change based on Tucker's comment from the
 meeting:
 
-   Tucker suggests that we could imagine a type invariant on the containers 
+   Tucker suggests that we could imagine a type invariant on the containers
    that Length(V) <= Capacity(V).
 
-This followed some discussion about shortcomings in the example you had. I 
-believe he was suggesting a different example that you could use, not a change 
-to the container's contracts. "we could imagine" doesn't sound to me to be a 
+This followed some discussion about shortcomings in the example you had. I
+believe he was suggesting a different example that you could use, not a change
+to the container's contracts. "we could imagine" doesn't sound to me to be a
 directive to change the actual container's definition.
 
-Note that there's nothing really wrong with adding this to the containers 
+Note that there's nothing really wrong with adding this to the containers
 other than the work required (both for me and for implementers). But it is
 already reflected in various postconditions where it could be relevant, so
-it seems like it would primarily be redundant (you only found a single 
+it seems like it would primarily be redundant (you only found a single
 postcondition that it would make redundant).
 
 >Modify A.18.6(16.7/5):
@@ -1468,43 +1388,43 @@
 >           Post => Length (Source) = Length (Target) [and then
 >                   Capacity (Target) >= Length (Source)];
 >
->[Author's note: This is a bug in the RM. Ordered maps do not have a Capacity 
+>[Author's note: This is a bug in the RM. Ordered maps do not have a Capacity
 >function!]
 
-I've fixed this, an obvious cut-and-paste error. No need to mention it 
-anywhere (few of the container contract things are written out anywhere other 
-than the RM and we can fix mistakes accordingly, at least until we publish a 
+I've fixed this, an obvious cut-and-paste error. No need to mention it
+anywhere (few of the container contract things are written out anywhere other
+than the RM and we can fix mistakes accordingly, at least until we publish a
 new Standard).
 
-I note that I concluded when contracting containers that it would have been a 
-lot easier had all of the containers had a Capacity of some sort. (I also 
-concluded that we needed a different cross-cut than the way the Sets/Maps are 
-organized -- probably, there should have been a set of operations that exist 
-in all six of the "normal" containers defined separately [there are about 
-30 or so], and then all of the other operations defined individually. That 
-would save a lot of text. Too late to do any of that, of course, it would 
+I note that I concluded when contracting containers that it would have been a
+lot easier had all of the containers had a Capacity of some sort. (I also
+concluded that we needed a different cross-cut than the way the Sets/Maps are
+organized -- probably, there should have been a set of operations that exist
+in all six of the "normal" containers defined separately [there are about
+30 or so], and then all of the other operations defined individually. That
+would save a lot of text. Too late to do any of that, of course, it would
 mainly be churn now and it would change all of the clause numbers.)
 
 >Modify A.18.20(5/3):
 >  type List (Capacity : Count_Type) is tagged private{,
 >     with Type_Invariant => Length (List) <= List.Capacity};
 
-This doesn't work as you wrote it, as the lead-in text says that this is only 
-describing the discriminant. Moreover, all of these are wrong anyway as they 
-seem to imply that this is the complete declaration, when this is only the 
-first line. That is, the existing example text (for all of the bounded forms) 
+This doesn't work as you wrote it, as the lead-in text says that this is only
+describing the discriminant. Moreover, all of these are wrong anyway as they
+seem to imply that this is the complete declaration, when this is only the
+first line. That is, the existing example text (for all of the bounded forms)
 should end with "..." and not ";", thus:
 
   type List (Capacity : Count_Type) is tagged private...
 
-as they already have 6 or more aspects specified after them. There's no intent 
-that this declaration change any of those aspects unless there is text 
-elsewhere to do that. (Note that the Bounded_Vectors have text to omit the 
+as they already have 6 or more aspects specified after them. There's no intent
+that this declaration change any of those aspects unless there is text
+elsewhere to do that. (Note that the Bounded_Vectors have text to omit the
 capacity from the stable properties.)
 
 >[Author's question: I presume that we only need to describe type invariants
 >for bounded containers where the unbounded forms do not already have such a
->type invariant? 
+>type invariant?
 
 Surely (if we do this at all).
 
@@ -1513,11 +1433,69 @@
 >use prefix form for bounded containers even though that is required
 >because Capacity is a discriminant, not a primitive operation? ...
 
-??? Bounded_Vectors, Bounded_Hashed_Maps, and Bounded_Hashed_Sets all still 
-have a function Capacity. So it's certainly OK to call it! Map.Capacity is 
-the discriminant, Capacity (Map) is the function. (There's a preference for 
-components, else there would have been a nasty incompatibility and the 
-possibility of "losing" access to components because of an inherited 
+??? Bounded_Vectors, Bounded_Hashed_Maps, and Bounded_Hashed_Sets all still
+have a function Capacity. So it's certainly OK to call it! Map.Capacity is
+the discriminant, Capacity (Map) is the function. (There's a preference for
+components, else there would have been a nasty incompatibility and the
+possibility of "losing" access to components because of an inherited
 primitive.)
+
+****************************************************************
+
+From: Brad Moore
+Sent: Tuesday, October 1, 2019  8:29 AM
+
+> ...
+>> This example shows that it can be possible to simplify the expression
+>> to a form that doesn't need the combiner, by using the map/reduce
+>> part of the value sequence to make both parameters of the reduction
+>> the same type.
+>
+> Didn't we consider that when we designed this feature? Didn't we
+> decide that the performance impact of eliminating the combiner would be unacceptable?
+> After all, the only reason for parallelizing something is to improve
+> the performance, and if doing that requires making a lot of expensive
+> copies then that doesn't make much sense. I'm certain that we
+> discussed this at least once and probably more than once. I'd suggest
+> going back through the mail/minutes on this topic (AI12-0242-1 &
+> AI12-0262-1) to see what we discussed about it in the past (rather
+> than reopening a discussion that we've had in the past).
+
+The example I was simplifying was originally intended to be an example showing
+the use of a combiner. Once I found that that example is better written
+without a combiner, I was struggling to find an example that needed a
+combiner. Most reducing problems dont.
+
+However, I think I have found an example that would likely also be good to
+include as an example in the RM.
+
+That is,
+
+Finding the set of prime numbers within some large range of integers.
+
+I am thinking of using a Set container for this problem.
+
+I will try to write up an example for this, and probably send out another
+version of the AI, with the additional example, as well as other correction
+suggested I've received so far.
+
+****************************************************************
+
+From: Brad Moore
+Sent: Tuesday, October 1, 2019  4:34 PM
+
+Here is a minor update to my AI. [This is version /06 - Editor.]
+
+I applied J.P's suggestion to raise Program_Error with "Impossible", if a
+Character is found in the String parameter that does not satisfy the
+precondition.
+
+I fixed up the paragraph numbers to match the current draft RM
+
+I removed adding type invariants to all the containers, because Randy suggests
+if we want to do that, that should be a different AI.
+
+I added a reduction example that uses a combiner function. (The prime number
+example)
 
 ****************************************************************

Questions? Ask the ACAA Technical Agent