ADA

Today in class I went over several example covering the programming language Ada.
I handed out several sample programs that you can use as reference for the lab that will be assigned next week.
At the end of the class I was showing some procedure calls that weren't on the handout. The following is an example of what I was covering:

Ada has procedures and functions.
Functions return a result so that the result can be used in an expression.

result := functioncall(value1 => X value2 => Y) + 45;

Procedures are called with a a procedure call statement as in
Ada.Text_IO.put(...);

Functions have parameters that are passed in only.

Procedures have three modes for paramters:

  1. Mode IN parameters - These are passed into the procedure and, inside the procedure, are treated as constants and may not be changed.
  2. Mode OUT paramters - These are computed in the procedure and passed out to the caller.
  3. Mode IN OUT paramters - These are passed into the procedure, possibly changed by it, and passed back out again (reference).
Example:
PROCEDURE Order(x: IN OUT Float; Y: IN OUT Float);

Procedure call:
Order (X=>Num1, Y=>Num2);

It's similar to a call by reference in C.
functionCall(&num1);

Here is a sample program (download and compile):

with Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

PROCEDURE mainprocedure IS

num1, num2 : Integer;

PROCEDURE inside(X: IN OUT Integer; Y: IN OUT Integer) IS

temp : Integer;

begin
  put(X);
  Ada.Text_IO.New_Line;
  put(Y);
  Ada.Text_IO.New_Line;
  temp := X;
  X := Y;
  Y := temp;

end inside;


begin
  
  num1 := 56;
  num2 := 299;
  Ada.Text_IO.put("Num1 before procedure call: ");
  put(num1);
  Ada.Text_IO.New_Line;
  Ada.Text_IO.put("Num2 before procedure call: ");
  put(num2);
  Ada.Text_IO.New_Line;

  inside(X => num1, Y => num2);

 Ada.Text_IO.put("Num1 after procedure call: ");
  put(num1);
  Ada.Text_IO.New_Line;
  Ada.Text_IO.put("Num2 after procedure call: ");
  put(num2);  
    Ada.Text_IO.New_Line;

end mainprocedure;