Congruent Parameter Lists [ HP Pascal/iX Programmer's Guide ] MPE/iX 5.0 Documentation
HP Pascal/iX Programmer's Guide
Congruent Parameter Lists
Two parameter lists are congruent if they have the same number of
parameters, and if parameters in the same positions are equivalent.
Two parameters are equivalent if any one of the following is true:
* They are value parameters of identical type.
* They are VAR parameters of identical type.
* They are parameters of procedure type with congruent parameter
lists.
* They are parameters of function type with congruent parameter
lists and identical result types.
* They are value conformant array parameters with equivalent
schemas.
* They are VAR conformant array parameters with equivalent schemas.
Two conformant array schemas are equivalent if all of the following are
true:
* Both are PACKED, or neither is PACKED.
* Corresponding index type specifications specify the same type.
* They have the same element type. If they have schemas for element
types, then those schemas are equivalent.
Example 1
This program uses procedure parameters whose own parameter lists do not
include conformant array parameters, function parameters, or other
procedure parameters.
PROGRAM prog;
VAR
r : real;
PROCEDURE proc (PROCEDURE procvar (x : integer; VAR y : char));
BEGIN
.
.
END;
FUNCTION func (PROCEDURE pvar (x : integer)) : real;
BEGIN
.
.
END;
PROCEDURE p1 (a : integer; VAR b : char); EXTERNAL;
PROCEDURE p2 (a : integer; VAR b : real); EXTERNAL;
PROCEDURE p3 (VAR a : integer; b : char); EXTERNAL;
PROCEDURE p4 (a,b : integer); EXTERNAL;
PROCEDURE p5 (a : integer); EXTERNAL;
BEGIN
proc(p1);
proc(p2); {illegal}
proc(p3); {illegal}
proc(p4); {illegal}
proc(p5); {illegal}
r := func(p5);
r := func(p4); {illegal}
r := func(p3); {illegal}
r := func(p2); {illegal}
r := func(p1); {illegal}
END.
The procedure proc has a procedure parameter, procvar. The parameter
list of procvar is congruent with the parameter list of the procedure p1,
but not with those of p2, p3, p4, or p5. Therefore, p1 can be an actual
parameter for procvar, but p2, p3, p4, and p5 cannot.
The function func has a procedure parameter, pvar. The parameter list of
pvar is congruent with the parameter list of the procedure p5, but not
with those of p1, p2, p3, or p4. Therefore, p5 can be an actual
parameter for pvar, but p1, p2, p3, and p4 cannot.
Example 2
This program uses function parameters whose own parameter lists do not
include conformant array parameters, procedure parameters, or other
function parameters.
PROGRAM prog;
VAR
r : real;
PROCEDURE proc (FUNCTION funcvar : (a,b,c : char) : Boolean);
BEGIN
.
.
.
END;
FUNCTION func (FUNCTION fvar : (a,b,c : char) : real) : real;
BEGIN
.
.
.
END;
FUNCTION f1 (x,y,z : char) : Boolean; EXTERNAL;
FUNCTION f2 (x,y,z : char) : real; EXTERNAL;
BEGIN
proc(f1);
proc(f2); {illegal}
r := func(f2);
r := func(f1); {illegal}
END.
The procedure proc has a function parameter, funcvar. The parameter list
of funcvar is congruent with the parameter list of the function f1, but
not with that of f2. Therefore, f1 can be an actual parameter for
funcvar, but f2 cannot.
The function func has a function parameter, fvar. The parameter list of
fvar is congruent with the parameter list of the function f2, but not
with that of f1. Therefore, f2 can be an actual parameter for fvar but
f1 cannot.
Example 3
This program uses a procedure parameter, procvar. The parameter list of
procvar includes conformant array parameters, w and x, another procedure
parameter, p1, and another function parameter, f1.
PROGRAM prog;
TYPE
itype = 1..10;
VAR
a : ARRAY [1..6] OF integer;
b : PACKED ARRAY [3..7] OF integer;
PROCEDURE alpha (m : integer); EXTERNAL;
FUNCTION beta (n : real) : integer; EXTERNAL;
PROCEDURE p (VAR cvar1 : ARRAY [a..b : itype] OF integer;
cvar2 : PACKED ARRAY [c..d : itype] OF integer;
PROCEDURE pvar (e : integer);
FUNCTION fvar (f : real) : integer;
); EXTERNAL;
PROCEDURE proc (PROCEDURE procvar
(VAR w : ARRAY [g..h : itype] OF integer;
x : PACKED ARRAY [i..j : itype] OF integer;
PROCEDURE p1 (x1 : integer);
FUNCTION f1 (x2 : real) : integer
)
);
BEGIN
procvar(a,b,alpha,beta);
END;
BEGIN
proc(p);
END.
The parameter lists of the formal procedure parameter procvar and the
procedure p are congruent: cvar1 and w are reference conformant array
parameters, cvar2 and x are value conformant array parameters, pvar and
function p1 are procedure parameters with congruent parameter lists, and
fvar and function f1 are function parameters with congruent parameter
lists.
Passing a routine as an actual parameter does not change its scope. If
it has access to a nonlocal entity before being passed as an actual
parameter, then it has access to that entity after being passed--even if
the entity is outside the scope of the routine to which the routine is
passed.
Example 4
PROGRAM prog (output);
PROCEDURE outer2 (PROCEDURE procvar (v : integer));
BEGIN {outer2}
procvar(7);
END; {outer2}
PROCEDURE outer1 (p : integer);
VAR
x : integer;
PROCEDURE inner (i : integer);
BEGIN {inner}
writeln(x,i,x+i,p);
END; {inner}
BEGIN {outer1}
x := 5;
outer2(inner);
END; {outer1}
BEGIN {prog}
outer1(2);
END. {prog}
The preceding program prints:
5 7 12 2
Because the procedure inner has access to the nonlocal variables x and p
before being passed to outer2, it has access to x and p after being
passed to outer2 (even though x and p are outside the scope of outer2).
MPE/iX 5.0 Documentation