Each of the examples below can be cut and pasted into a file in notepad.
The ada comment symbol is two hyphens. Each ada example should be saved using the name following the word procedure and the extension should be .adb
with ada.text_io; -- allows text values to be input and output (i.e characters and strings)
with ada.integer_text_io; -- allows integers to be input and output
procedure adaParameters is
a, b : integer;
procedure swap (c : in out integer; d : in out integer) is
temp : integer;
begin
ada.integer_text_io.put (c);
ada.integer_text_io.put( d);
ada.text_io.new_line;
temp := c;
c := d;
d := temp;
ada.integer_text_io.put (c);
ada.integer_text_io.put( d);
ada.text_io.new_line;
end swap;
begin
a := 5;
b := 18;
ada.integer_text_io.put (a);
ada.integer_text_io.put (b);
ada.text_io.new_line;
swap (a,b);
ada.integer_text_io.put (a);
ada.integer_text_io.put (b);
ada.text_io.new_line;
end adaParameters
with ada.text_io; -- allows text values to be input and output (i.e characters and strings)
with ada.integer_text_io; -- allows integers to be input and output
procedure adaParameters13 is
a, b : integer;
procedure swap (c : out integer; d : out integer) is
temp : integer;
begin
ada.text_io.put (" here are c and d on entry to swap ");
ada.integer_text_io.put (c);
ada.integer_text_io.put( d);
ada.text_io.new_line;
temp := c;
c := d;
d := temp;
ada.text_io.put (" here are c and d after swapping in swap ");
ada.integer_text_io.put (c);
ada.integer_text_io.put( d);
end swap;
begin
a := 5;
b := 18;
ada.integer_text_io.put (a);
ada.integer_text_io.put (b);
ada.text_io.put_line (" these were the original values ");
swap (a,b);
ada.text_io.put_line (" these were the values returned ");
ada.integer_text_io.put (a);
ada.integer_text_io.put (b);
end adaParameters13;
with ada.text_io; -- allows text values to be input and output (i.e characters and strings)
with ada.integer_text_io; -- allows integers to be input and output
procedure adaParameters17 is
a, b : integer;
procedure swap (c :IN integer; d : IN integer) is
temp : integer;
temp1 : integer;
begin
temp1 := 79;
c := temp1;
ada.integer_text_io.put (temp1, c);
ada.text_io.new_line;
ada.integer_text_io.put (c);
ada.integer_text_io.put( d);
temp := c;
ada.integer_text_io.put (temp);
c := d;
ada.integer_text_io.put (c);
d := temp;
ada.integer_text_io.put (d);
ada.text_io.new_line (2);
end swap;
begin
a := 5;
b := 18;
ada.integer_text_io.put (a);
ada.integer_text_io.put (b);
swap (a,b);
ada.integer_text_io.put (a);
ada.integer_text_io.put (b);
ada.text_io.new_line;
end adaParameters17;
--this program shows that even when parameters are in out (value/result)
-- which appears to behave like pass by reference that when the
-- procedure terminates abnormally, the values are not copied back to
-- the calling program
-- the purpose of the divide by 0 is to raise an exception which is
-- not caught in the block where it occurs, causing the procedure to be
-- exited abnormally.
with ada.text_io; -- allows text values to be input and output (i.e characters and strings)
with ada.integer_text_io; -- allows integers to be input and output
procedure adaParameters4 is
a, b : integer;
procedure swap (c :in out integer; d : in out integer) is
temp : integer;
begin
c := 5;
d := 18;
ada.integer_text_io.put (c);
ada.integer_text_io.put( d);
temp := c;
c := d;
d := temp;
ada.integer_text_io.put (c);
ada.integer_text_io.put( d);
d := c /0;
end swap;
begin
a := 5;
b := 18;
ada.integer_text_io.put (a);
ada.integer_text_io.put (b);
begin
swap (a,b);
exception
when constraint_error => ada.text_io.put (" oops can't divide by 0 ");
end;
ada.integer_text_io.put (a);
ada.integer_text_io.put (b);
end adaParameters4;
program pascalParameters (intput, output);
var a,b : integer;
procedure swap (var c : integer; var d: integer);
var temp : integer;
begin
temp := c;
c := d;
d := temp;
writeln (' c is ', c , ' and d is now ', d);
end;
begin
a := 5;
b := 18;
writeln ('a is initially ', a, ' and b is initially ', b);
swap (a,b);
writeln (' after swap a is ', a, ' and b is ', b);
end.
program pascalParameters3 (intput, output);
var a,b : integer;
procedure swap ( c : integer; var d: integer);
var temp : integer;
begin
temp := c;
c := d;
d := temp;
writeln (' c is ', c , ' and d is now ', d);
end;
begin
a := 5;
b := 18;
writeln ('a is initially ', a, ' and b is initially ', b);
swap (a,b);
writeln (' after swap a is ', a, ' and b is ', b);
end.
program pascalParameters4 (intput, output);
var a,b : integer;
procedure swap (c : integer; d: integer);
var temp : integer;
begin
temp := c;
c := d;
d := temp;
writeln (' c is ', c , ' and d is now ', d);
end;
begin
a := 5;
b := 18;
writeln ('a is initially ', a, ' and b is initially ', b);
swap (a,b);
writeln (' after swap a is ', a, ' and b is ', b);
end.
IA = 5
IB = 18
WRITE (6,*) IA, IB
CALL SWAP (IA, IB)
WRITE (6,*) IA, IB
STOP
END
SUBROUTINE SWAP ( IC, ID)
WRITE (6,*) IC, ID
ITEMP = IC
IC = ID
ID = ITEMP
WRITE (6,*) IC,ID
END
**************************************************