Procedure References

A procedure reference is any reference followed by an argument list consisting of a parenthetical list of expressions separated by commas or followed by an empty argument list (). A procedure reference that returns a value is called a function reference. A procedure reference that does not return a value is called a subroutine reference.

If an argument list or empty argument list is given, the referenced name must be declared as an entry either by appearing as a label prefix on a PROCEDURE statement or by a DECLARE statement. Unless the reference is part of a CALL statement, the referenced entry must return a value. If the reference is part of a CALL statement, the entry must not return a value; therefore, a procedure that returns a value must always be called as a function, and a procedure that does not return a value must always be called as a subroutine.

A name declared as an entry is called only when it is referenced with an argument list or when it is called by a CALL statement. A function that has no parameters must be referenced with an empty argument list.

Except when it is part of a CALL statement, a reference to an entry written without an argument list is a reference to the entry value, rather than a function reference that calls the entry.

The following example demonstrates a range of procedure references.

DECLARE F ENTRY RETURNS(POINTER);
DECLARE G ENTRY(FIXED) RETURNS(FLOAT); 
DECLARE V ENTRY VARIABLE RETURNS(POINTER); 
DECLARE P POINTER, X FLOAT;
   . 
   . 
   .
P = F(); 
V = F;
X = G(0);

In this example, a reference to F() calls F and produces a pointer value. A reference to F is a reference to the entry value of F and can be assigned to the entry variable V. A reference to G is also a reference to an entry value and does not call G. G is called by references containing an argument list.

An array of entry variables may be referenced with subscripts and with an argument list. In this case, the argument list follows the subscript fist, as shown in the following example:

DECLARE E(5) ENTRY(FIXED) VARIABLE 
      RETURNS(POINTER);

According to E's declaration, E is a reference to the entire array of entry values. E (k) (j) is a pointer valued function reference that calls E (kf, passing it the argument j. E (k) is an entry value that may be passed to an entry parameter or assigned to an entry variable. If E had been declared without parameters, E (k) would have to be invoked using an empty argument list — E(k) () .