-- Chapter 30 - Programming exercise 1 generic type ITEM is range <>; -- integer class only procedure Exchange_Data(X,Y : in out ITEM); procedure Exchange_Data(X,Y : in out ITEM) is Temp : ITEM; begin Temp := X; X := Y; Y := Temp; end Exchange_Data; -- This is the beginning of the main program which uses the generic -- procedure defined above. with Exchange_Data; with Ada.Text_IO; use Ada.Text_IO; procedure CH30_1 is package Int_IO is new Ada.Text_IO.Integer_IO(INTEGER); use Int_IO; type MY_INT is new INTEGER range 1..128; subtype SUB_INT is INTEGER range 1.. 55; procedure SwapInt is new Exchange_Data(INTEGER); procedure SwapNew is new Exchange_Data(MY_INT); procedure SwapSub is new Exchange_Data(SUB_INT); Index1 : INTEGER := 17; Index2 : INTEGER := 33; Limit1 : MY_INT := 3; Limit2 : MY_INT := 7; Small1 : SUB_INT := 13; Small2 : SUB_INT := 27; begin SwapInt(Index1,Index2); SwapNew(Limit1,Limit2); SwapSub(Small1,Small2); SwapInt(Small1,Small2); Put(Index1); Put(Index2); New_Line; Put(INTEGER(Limit1)); Put(INTEGER(Limit2)); New_Line(2); SwapInt(Index1,INTEGER(Limit1)); SwapNew(MY_INT(Index2),Limit2); Put(Index1); Put(Index2); New_Line; Put(INTEGER(Limit1)); Put(INTEGER(Limit2)); New_Line(2); end CH30_1; -- Note that it is legal to instantiate a copy of the generic -- procedure for the subtype. It is a waste of code however, -- because the procedure for the parent type can be used for -- the subtype as illustrated in line 44. -- Result of Execution -- 33 17 -- 7 3 -- -- 7 3 -- 33 17