Formal Parameter Part

<formal parameter part>

── ( ──<formal parameter list>── ) ── ; ─┬──────────────┬──────────────►
                                         └─<value part>─┘
                       ┌◄─────── ; ──────┐
►─┬──────────────────┬─┴─<specification>─┴─────────────────────────────┤
  └─<reference part>─┘

<formal parameter list>

  ┌◄─┬── , ───────────────────┬─┐
  │  └◄─<parameter delimiter>─┘ │
──┴─<formal parameter>──────────┴──────────────────────────────────────┤

<formal parameter>

──<identifier>─────────────────────────────────────────────────────────┤

<value part>

          ┌◄───── , ─────┐
── VALUE ─┴─<identifier>─┴─ ; ─────────────────────────────────────────┤

<reference part>

              ┌◄───── , ─────┐
── REFERENCE ─┴─<identifier>─┴─ ; ─────────────────────────────────────┤

The formal parameter part lists the items to be passed in as parameters when the procedure is invoked. A formal parameter part is optional. Every formal parameter for a procedure must appear in a specification.

If the identifier of a formal parameter is declared again as a local variable, the identifier gets local significance. This makes the actual parameter that corresponds to it inaccessible throughout this inner scope. Any reference to the parameter identifier actually is a reference to the local variable.

For maximum efficiency, as many formal parameters as possible should be call-by-value, and each specified lower bound should have a value of 0 (zero).

To ensure that a parameter is passed call-by-reference, the parameter name must appear in the <reference part> of the parameter description. Constants and arithmetic expressions cannot be passed to parameters whose name appears in the reference part.

If a formal parameter is call-by-reference and the actual parameter being passed to it is itself a parameter and is call-by-name, then evaluation of the call-by-name parameter is done in order to generate the call-by-reference parameter. This ensures that any expressions evaluated due to an accidental entry generated for the call-by-name parameter are evaluated only once for the call-by-reference parameter.

The value part specifies which formal parameters are to be call-by-value. When a formal parameter is call-by-value, the formal parameter is assigned the value of the corresponding actual parameter when the procedure is invoked. Thereafter, the formal parameter is handled as a variable that is local to the procedure body. That is, any change made to the value of a call-by-value formal parameter has no effect outside the procedure body.

For more information on <parameter delimiter>, see Language Components.

Only arithmetic, Boolean, complex, designational, pointer, and string expressions can be passed as actual parameters to call-by-value formal parameters. These expressions are evaluated once before entry into the procedure body.

Formal parameters not listed in the value part are call-by-reference, except for Boolean, complex, dinteger, double, integer, and real parameters, which are call-by-name, unless they are listed in the reference part. Wherever a call-by-name formal parameter appears in the procedure body, the formal parameter is, in effect, replaced by the actual parameter itself and not by the value of the actual parameter. A call-by-name formal parameter is essentially global to the procedure body, because any change made to its value within the procedure body also changes the value of the corresponding actual parameter outside the procedure body. If the formal parameter is a complex call-by-name parameter and the actual parameter is not of type COMPLEX, an assignment within the procedure body to the formal parameter causes the program to discontinue with a fault.

An expression can be passed as an actual parameter to a call-by-name formal parameter. This situation results in a thunk, or accidental entry. A thunk is a compiler-generated typed procedure that calculates and returns the value of the expression each time the formal parameter is used. This situation can be time-consuming if the formal parameter is repeatedly referenced. In addition, a fault occurs if an attempt is made to store into that parameter.

The default mode of passing a string is call-by-reference instead of call-by-name. Any string expression can be passed to a call-by-reference string formal parameter. When a string variable or a subscripted string variable is passed as an actual parameter to a call-by-reference string formal parameter, a reference to the actual string is passed. If the value of the formal parameter is changed within the procedure body, the actual string is also changed.

If any other form of string expression is passed as an actual parameter to a call-by-reference string formal parameter, the string expression is evaluated once at the time the expression is passed, and a reference to the value of the expression is passed to the called procedure. This value can be altered by the called procedure. However, any change in the value of the formal parameter within the procedure body has no effect outside the procedure body. A string expression cannot be passed as an actual parameter to a call-by-name parameter of a procedure in a PROCESS or CALL statement.