--  Predefined operators and enumeration literals as subprograms (RM 8.5.4(2), 4.1.3, 12.6):
--  renamed, called by expanded name, and as generic formals' defaults; a call is the
--  operation, checked where it is.
with Ada.Text_IO;
procedure Main is
   package P is
      type Int is range 1 .. 100;
      type Color is (Red, Blue);
   end P;
   --  the operators of P's types by their expanded names, with no use clause
   function "+" (L, R : P.Int) return P.Int renames P."+";
   function Same (L, R : P.Color) return Boolean renames P."=";
   function Plus (L, R : Integer) return Integer renames "+";
   function Times (L, R : Integer) return Integer renames Standard."*";
   function Minus (X : Integer) return Integer renames "-";
   type Color is (Red, Green, Blue);
   function Teal return Color renames Blue;
   function No return Boolean renames False;
   generic
      with function Join (X, Y : String) return String is "&";
      with function Low return Color is Red;
   function Describe (S : String) return String
     with Pre => S'First = 1 and S'Length < 100;
   function Describe (S : String) return String is (Join (S, "!") & Color'Image (Low));
   function Colors is new Describe;
   A : P.Int := 2;
   N : Integer := 6;
begin
   A := A + 3;                         --  the renaming, P's predefined "+"
   if P."=" (A, 5) and then P."/=" (P.Red, P.Blue) and then Same (P.Blue, P.Blue) then
      A := P."+" (A, 1);
   end if;
   N := Plus (N, Times (2, 3)) + Minus (1);
   pragma Assert (P."=" (A, 6) and N = 11);
   pragma Assert (Teal = Blue and not No);
   Ada.Text_IO.Put_Line (P.Int'Image (A) & Integer'Image (N) & " " & Color'Image (Teal) & " " & Colors ("is "));
end Main;
