Contents | Prev | Next

13.5 Allow relaxed parameter list congruity

As an extension to Standard Pascal, Irie Pascal relaxes the rules when deciding whether two formal parameter lists are congruent. NOTE:This extension is the only one that can not be disabled.

A rarely used feature of the Pascal language is the ability to pass functions and procedures to other functions and procedures. Functions are passed using functional parameters, and procedures are passed using procedural parameters. Functional and procedural parameters come in two forms, actual and formal, just like the other kinds of parameters (value and variable parameters). Actual functional parameters specify the functions being passed, and formal functional parameters are used to reference the functions being passed, inside the receiving functions or procedures. In a similar way, actual procedural parameters specify the procedures being passed, and formal procedural paramters are used to reference the procedures being passed, inside the receiving functions or procedures.

The formal parameter list of the function specified by an actual functional parameter must be congruent with the formal parameter list of the corresponding formal functional parameter. The formal parameter list of the procedure specified by an actual procedural parameter must be congruent with the formal parameter list of the corresponding formal procedural parameter.

Standard Pascal takes into account the formal parameter sections when deciding whether two formal parameter lists are congruent, and requires that they must have the same number of formal parameter sections (amoung other requirements). Irie Pascal ignores formal parameter sections and compares individual parameters.

So for example, Irie Pascal considers the following program to be valid, but Standard Pascal does not.

program functional(output);

   function Operation(function op(a, b : integer) : integer; i, j : integer) : integer;
   begin
      Operation := op(i, j);
   end;

   function Add(c : integer; d : integer) : integer;
   begin
      Add := c + d;
   end;

begin
   writeln(Operation(Add, 3, 1));
end.

The formal parameter list of the function Add contains two formal parameter sections:

   c : integer

and

   d : integer

while the formal parameter list of the formal functional parameter op contains one formal parameter section:

   a, b : integer

and so Standard Pascal does not consider the two formal parameter lists to be congruent, and therefore the following

   Operation(Add, 3, 1)

is invalid. Irie Pascal compares corresponding formal parameters idividually, so

   c : integer
    is compared with the first parameter in

   a, b : integer

and they are both value parameters of integer type, and

   d : integer

is compared with the second parameter in

   a, b : integer

and again they are both value parameters of integer type, so Irie Pascal considers the two formal parameter lists to be congruent, and therefore the following

   Operation(Add, 3, 1)

is valid.

Contents | Prev | Next