--  Sources walked in step (T25b, Verada's extension, stream-combinators.md 6.3): `for X of A,
--  Y of B` ends with the shorter; a range in step with an array enumerates its components.
pragma Extensions_Allowed (On);
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   subtype Small is Integer range -100 .. 100;
   type Arr is array (Positive range <>) of Small;

   --  the dot product, over the shorter
   function Dot (A, B : Arr) return Integer is
     ([for X of A, Y of B => X * Y]'Reduce ("+", 0))
   with Pre => A'Length <= 1000;

   --  the products where the first is positive
   function Positive_Dot (A, B : Arr) return Integer is
     ([for X of A, Y of B when X > 0 => X * Y]'Reduce ("+", 0))
   with Pre => A'Length <= 1000;

   A : constant Arr := (1, 2, 3, 4);
   B : constant Arr := (10, -20, 30);
   R : constant Arr (5 .. 7) := (7, 8, 9);
begin
   Put_Line (Integer'Image (Dot (A, B)) & Integer'Image (Positive_Dot (B, A)) & Integer'Image (Dot (A, R)));
   --  enumerate: a counter in step with the components
   for I in 1 .. 10, X of R loop
      Put_Line (Integer'Image (I) & ":" & Integer'Image (X));
   end loop;
end Main;
