with Ada.Text_IO;

procedure Main is
   type State is (Idle, Busy, Done);
   subtype Small is Integer range -100 .. 100;
   type Scores is array (1 .. 3) of Small;
   type Point is record
      X, Y : Small := 0;
   end record;

   Values : constant Scores := [1, 2, 3];
   Sum : constant Integer := Values'Reduce ("+", 0);
   Origin : constant Point := (X => 7, Y => 8);
   Shifted : constant Point := (Origin with delta X => 10);
   Count : Natural := 0;
   Code : constant Integer := 16#2A#;
   Quoted : constant String := "say ""hello""";

   function Clamp (Value, Low, High : Integer) return Integer
     with Pre => Low <= High,
          Post => Clamp'Result = (if Value < Low then Low elsif Value > High then High else Value)
   is
   begin
      if Value < Low then
         return Low;
      elsif Value > High then
         return High;
      else
         return Value;
      end if;
   end Clamp;

   procedure Add (Value : in out Natural; Amount : Natural)
     with Pre => Amount <= Natural'Last - Value,
          Post => Value = Value'Old + Amount
   is
   begin
      Value := Value + Amount;
   end Add;

   generic
      type Item is private;
   function Choose (First : Boolean; Left, Right : Item) return Item;

   function Choose (First : Boolean; Left, Right : Item) return Item is
   begin
      if First then
         return Left;
      else
         return Right;
      end if;
   end Choose;

   function Choose_Integer is new Choose (Integer);
begin
   Add (Count, Amount => 2);
   pragma Assert (Count = 2);
   pragma Assert (Clamp (42, 0, 10) = 10);
   pragma Assert (Choose_Integer (True, Origin.X, Origin.Y) = 7);
   pragma Assert ((for all X of Values => X > 0));
   pragma Assert (Shifted.X = 10);
   pragma Assert ((-7) mod 3 = 2);
   pragma Assert (Code = 42);
   pragma Assert (Quoted'Length = 11);
   for I in Values'Range loop
      pragma Assert (Values(I) > 0);
   end loop;
   case Idle is
      when Idle =>
         Count := Count + 1;
      when Busy | Done =>
         null;
   end case;
   Ada.Text_IO.Put_Line ("syntax:" & Natural'Image (Count));
   Ada.Text_IO.Put_Line ("sum:" & Integer'Image (Sum));
end Main;
