home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 28 - Program 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 Text_IO;
- use Text_IO;
-
- procedure SwapSome 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);
-
- 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 SwapSome;
-
-
-
-
- -- Result of Execution
-
- -- 33 17
- -- 7 3
- --
- -- 7 3
- -- 33 17
-
-