-- Chapter 31 - Program 2 package EasyPkg is procedure Trade_Values (X, Y : in out INTEGER); generic type MY_REAL_TYPE is digits <>; package Nested_Generic is function Average_Values (X, Y : MY_REAL_TYPE) return MY_REAL_TYPE; end Nested_Generic; end EasyPkg; package body EasyPkg is procedure Trade_Values (X, Y : in out INTEGER) is Temp : INTEGER; begin Temp := X; X := Y; Y := Temp; end Trade_Values; package body Nested_Generic is function Average_Values (X, Y : MY_REAL_TYPE) return MY_REAL_TYPE is begin return (X + Y) / 2.0; end Average_Values; end Nested_Generic; end EasyPkg; with Ada.Text_IO, EasyPkg; use Ada.Text_IO, EasyPkg; procedure NestPkg is type MY_NEW_FLOAT is new FLOAT digits 6; package Funny_Stuff is new EasyPkg.Nested_Generic(MY_NEW_FLOAT); use Funny_Stuff; package Usual_Stuff is new Nested_Generic(FLOAT); use Usual_Stuff; Int1 : INTEGER := 12; Int2 : INTEGER := 35; Real1 : FLOAT; My_Real1 : MY_NEW_FLOAT; begin Trade_Values(Int1, Int2); -- Uses Trade_Values directly EasyPkg.Trade_Values(Int1, Int2); -- Uses Trade_Values directly -- Usual_Stuff.Trade_Values(Int1, Int2); -- Illegal -- Funny_Stuff.Trade_Values(Int1, Int2); -- Illegal Real1 := Average_Values(2.71828, 3.141592); Real1 := Average_Values(Real1, 2.0 * 3.141592); My_Real1 := Average_Values(12.3, 27.345); My_Real1 := Average_Values(My_Real1, 2.0 * 3.141592); My_Real1 := Funny_Stuff.Average_Values(12.3, 27.345); end NestPkg; -- Result of execution -- (There is no output from this program)