home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 28 - Programming exercise 2
- 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 Text_IO;
- use Text_IO;
-
- procedure CH28_2 is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- type MY_INT is new INTEGER range 1..128;
-
- procedure SwapInt is new Exchange_Data(INTEGER);
- procedure SwapNew is new Exchange_Data(MY_INT);
- procedure SwapFlt is new Exchange_Data(FLOAT);
-
- Index1 : INTEGER := 17;
- Index2 : INTEGER := 33;
- Limit1 : MY_INT := 3;
- Limit2 : MY_INT := 7;
-
- begin
-
- SwapInt(Index1,Index2);
- SwapNew(Limit1,Limit2);
-
- 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 CH28_2;
-
-
-
-
- -- Result of Execution
-
- -- Compile error,
- -- Line 29 - must instantiate with integer type for "ITEM".
-
-