-- Demonstrates using a record type as a parameter
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
with Ada.Text_IO; use Ada.Text_IO;
procedure paramRecords is
type Pair is record
x: Integer;
y: Integer;
end record;
procedure putPair(p: Pair) is
begin
put(p.x);
put(p.y);
new_line;
end putPair;
-- In out parameter pair
procedure swapPair(p1, p2: in out Pair) is
temp: constant Pair := p1;
begin
p1 := p2;
p2 := temp;
end swapPair;
-- Does this swap differ from the other?
-- Would they differ if this were java?
procedure swapPairElements(p1, p2: in out Pair) is
tempx: constant Integer := p1.x;
tempy: constant Integer := p1.y;
begin
p1.x := p2.x;
p1.y := p2.y;
p2.x := tempx;
p2.y := tempy;
end swapPairElements;
p1: Pair := (1, 2);
p2: Pair := (3, 4);
begin
putPair(p1);
putPair(p2);
new_line;
swapPair(p1, p2);
putPair(p1);
putPair(p2);
new_line;
swapPairElements(p1, p2);
putPair(p1);
putPair(p2);
end paramRecords;
-- Output
-- 1 2
-- 3 4
--
-- 3 4
-- 1 2
--
-- 1 2
-- 3 4