pragma Extensions_Allowed (On);
--  APL text (T32b): Verada functions of scalars are APL functions, lifted elementwise, their
--  preconditions checked at each element and their results' subtypes bounding a sum; a
--  function of a vector applied to each row of a matrix (its cells of rank 1); proved
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   subtype Small is Integer range -100 .. 100;
   type Vector is array (Positive range <>) of Integer;
   type Smalls is array (Positive range <>) of Small;
   X : constant Smalls := (1, -2, 3);
   Y : constant Smalls := (10, 20, 30);
   subtype Square_Range is Integer range 0 .. 10_000;
   function Square (V : Small) return Square_Range is (V * V);
   function Clamp (V : Integer; Limit : Natural) return Integer is
     (if V > Limit then Limit elsif V < -Limit then -Limit else V)
   with Pre => Limit <= 1_000;
   type Matrix is array (Positive range <>, Positive range <>) of Small;
   A : constant Matrix := ((1, 2, 3), (4, 5, 6));
   function Spread (V : Smalls) return Integer is (V (V'Last) - V (V'First))
     with Pre => V'Length > 0;
   procedure Show (V : Vector) is
   begin
      for E of V loop
         Put (Integer'Image (E));
      end loop;
      New_Line;
   end Show;
   Squares : constant Vector := APL ("Square X");
   Clamped : constant Vector := APL ("Y Clamp 15");
   Sum_Squares : constant Integer := APL ("+/ Square X");
   Mixed : constant Vector := APL ("X + Square¨ X");
   Spreads : constant Vector := APL ("Spread A");
begin
   Show (Squares);
   Show (Clamped);
   Put_Line (Integer'Image (Sum_Squares));
   Show (Mixed);
   Show (Spreads);
end Main;
