Function Calls [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation
HP Pascal/iX Reference Manual
Function Calls
A function call invokes the block of a standard or declared function and
returns a value to the calling point of the program. Because an operator
can perform some action on this value, a function result is an
expression.
A function call consists of a function identifier and an optional list of
actual parameters in parentheses. The actual parameters must match the
formal parameters in number, type, and order. The function result has
the type specified in the function heading. Actual value parameters are
expressions that must be assignment compatible with the formal value
parameters or, in the case of value conformant array parameters, conform
with the conformant array schema.
Actual reference parameters are variables that must be type identical
with the formal variable parameters or, in the case of variable
conformant array parameters, conform with the conformant array schema.
Components of a packed structure may not appear as actual variable
parameters.
Actual procedural or functional parameters are the names of declared
procedures or functions. Standard functions or procedures are not legal
actual parameters.
The parameter list, if any, of an actual procedural or functional
parameter, must be congruent with the parameter list of the formal
procedural or functional parameter. For more information, see the
section on Procedures in this chapter.
Functions may call themselves recursively. Refer to "Recursion"
earlier in this chapter for more details.
If an actual functional or procedural parameter, upon invocation,
accesses any entity non-locally, then the entity accessed is one that is
accessible to the function or procedure when its identifier is passed.
For example, suppose Procedure A uses the non-local variable x. If A is
passed as a parameter to Function B, then it still has access to x, even
if x is otherwise inaccessible in B.
If the function result is a structured type, then the function call may
select a particular component as the result. This requires the use of an
appropriate selector.
Example
PROGRAM show_function (input,output);
VAR
n,
coef,
answer: integer;
FUNCTION fact (p: integer) : integer;
BEGIN
IF p > 1 THEN
fact := p * fact (p-1)
ELSE fact := 1
END;
FUNCTION binomial_coef (n, r: integer) : integer;
BEGIN
binomial_coef := fact (n) DIV (fact (r) * fact (n-r))
END;
BEGIN { show_function }
read(n);
FOR coef := 0 TO n DO
writeln (binomial_coef (n, coef));
END. { show_function }
MPE/iX 5.0 Documentation