The Ada Program: passing.adb

  1 -- passing.adb:  parameter-passing mechanism effects program
  2 
  3 with Ada.Text_IO, Ada.Integer_Text_IO;
  4 use Ada;
  5 
  6 procedure Passing is
  7 
  8    type Matrix is array (Positive range <>) of Integer;
  9 
 10    A, B: Matrix := (1=>7);
 11 
 12    procedure Test (X: in Matrix; Y: out Matrix) is
 13    begin
 14       Text_IO.Put ("A,X,Y before:  ");
 15       Integer_Text_IO.Put (A(1), Width=>4);  -- non-local reference
 16       Integer_Text_IO.Put (X(1), Width=>4);
 17       Integer_Text_IO.Put (Y(1), Width=>4);
 18       Y(1) := 997;
 19       Text_IO.Put (".  A,X,Y after change to Y:  ");
 20       Integer_Text_IO.Put (A(1), Width=>4);  -- non-local reference
 21       Integer_Text_IO.Put (X(1), Width=>4);
 22       Integer_Text_IO.Put (Y(1), Width=>4);
 23       Text_IO.New_Line;
 24    end Test;
 25 
 26 begin
 27    Text_IO.Put_Line ("A in, B out.");
 28    Test (A,B);
 29    Text_IO.Put_Line ("A in, A out.");
 30    Test (A,A);
 31 
 32 end Passing;