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

Differences between 1.1 and version 1.2
Log of other versions for file ai12s/ai12-0188-1.txt

--- ai12s/ai12-0188-1.txt	2016/06/03 05:41:02	1.1
+++ ai12s/ai12-0188-1.txt	2017/11/30 04:18:02	1.2
@@ -323,3 +323,109 @@
 [Editor's note: This thread continues in AI12-0190-1, since it has much more
 to do with general lambdas than it does with this proposal.]
 
+****************************************************************
+
+From: Brad Moore
+Sent: Saturday, June 11, 2016  9:20 PM
+
+> Sure, but it *still* doesn't look like a loop.
+[Editor's note: The above is from a thread filed in AI12-0189-1.]
+
+The last thing I remember Jeff say before we headed back to our rooms after
+dinner last night was something about having pleasant dreams about generators.
+...  Thanks Jeff....
+
+So here it is 3am, my thoughts returned to this email, and I am thinking this
+is related to generators, which might be worth capturing if we are to discuss
+tomorrow.
+
+I think the Java idea could be adapted to syntax that looks more like a loop,
+and it strikes me that the mechanism being used can be considered as a
+generator approach.
+
+Before I describe, first some examples of what it might look like.
+
+The above example
+
+   Total : Integer := 0;
+
+    for I of Iterate(1, N).Parallel.Sum(Total) loop
+       Total := Total + I;
+   end loop;
+
+Iterate(1,N) is a library call to a generator that creates a single "stream"
+value that includes the start, end, and a result value (of type Integer) of
+the iteration
+
+Parallel is another library call that produces a generator and takes a
+"stream" value and splits it into several substream values of "Chunks" of
+iterations. The number of chunks is likely determined based on the number of
+available cores. To get a sequential loop, from the above, you could just
+delete the .Parallel.
+
+Sum is an instantiation of a  "stream" collector library call that calls the
+input generator produced by Parallel, to retrieve chunks, then produces in
+parallel for each generator value, which is an integer. The parameter of Sum
+(ie Total) is a external variable that is updated by the overall result. It
+also happens to be the name of a in out parameter that is passed into a
+callback that is represented by the loop body.
+
+The loop body in fact is updating the local copy of the partial sum, and the
+reduction occurs inside the Sum collector procedure, which updates the real
+result.
+
+The collector generic itself is can be a generic procedure that has two generic
+formals, the identity value for the reduction, and the reducer function.
+
+procedure Add is new Collector(Result_Type => Integer, Reduce => "+",
+Identity => 0); Add could be a set of preinstantiated collectors that are
+available for common use, but the programmer could create user-defined
+collectors as well.
+
+The callback probably takes also as parameters the start and end range of the
+iteration, but the syntactic sugar of this loop syntax, hides that.
+
+Now consider some other examples.
+
+  -- Iterating through a map container by keys.
+  for Pair of Container.Keys  loop
+         Put_Line(Key_Type'Image(Pair.Key) & " => " &
+           Elem_Type'Image(Pair.Elem));
+   end loop;
+
+Keys is a function that produces a generator for the name value pairs of the
+container
+
+
+  -- Iterating through a map container to produce parallel sum of elements.
+
+  Total : Integer := 0;
+
+  for Element of Container.Elements.Parallel.Sum(Total)  loop
+         Total := Total + Element;
+   end loop;
+
+Elements is a function that produces a generator whose value is an element of
+the container, rather than a name value pair.
+
+-- Ada Environment variables.
+
+    for Pair of Ada.Environment_Variables.Iterate loop
+       Put_Line (Pair.Name & " => " & Pair.Value);
+    end loop;
+
+In this case, we'd probably need to define a Name_Value_Pair_Type and probably
+a new Iterate subprogram that works with this type.
+
+
+Anyway, please keep in mind it is 4am, I should probably know better to
+compose emails at this time, as this might seem like a half-baked mess in the
+morning. But it strikes me that this might be a nice mixture of ideas from
+Tuck's loop body syntax, the generator proposal, and what Ive been thinking
+of lately as an alternative.
+
+The Java stream approach seems to be very flexible and powerful for
+expression, but the Ada take on this would be better for Ada if it can make
+it mechanism look more like a loop. 
+
+****************************************************************

Questions? Ask the ACAA Technical Agent