Contents | Prev | Next | Index


Formal Parameters

Formal parameters are identifiers declared in the formal parameter list of a procedure. Each formal parameter corresponds to an actual parameter as specified in the procedure call. This correspondence between formal and actual parameters is established during the procedure call.

There are two kinds of parameters: Value parameters and variable parameters. A variable parameter is indicated in the formal parameter list by the presence of the keyword VAR. This keyword is absent for value parameters. A value parameter is like local variable to which the value of the corresponding actual parameter is assigned as an intial value. Variable parameters correspond to actual parameters which are variable designators, and they stand for these variables. The compiler uses internally a reference to the actual variable for a formal variable parameter.

The scope of a formal parameter is the same as those for other local variables: It extends from its point of declaration to the end of the procedure block in which it is declared.

A function procedure without parameters must have an empty parameter list, and it must be called by a function designator whose actual parameter list is empty, too. The result type can neither be a record nor an array.

Due to Java restrictions in this compiler, if for a function procedure there is a variable parameter of a basic type, any changes to it inside the procedure body are not reflected to the actual parameter variable outside the function procedure. Side effects of this nature from function calls should be avoided anyway. Also because of Java restrictions, any changes to a formal variable parameter of a basic type inside a proper procedure won't be reflected to the actual parameter variable outside the procedure until completetion of the procedure execution.

formal_parameters ::= ( )
                  ::= ( ) : qualident
                  ::= ( fp_section_list )
                  ::= ( fp_section_list ) : qualident
fp_section_list   ::= fp_section_list ; fp_section
                  ::= fp_section
fp_section        ::= VAR id_list : formal_type
                  ::= id_list : formal_type
id_list           ::= id_list , <identifier>
                  ::= <identifier>
formal_type       ::= qualident
                  ::= open_array qualident
open_array        ::= open_array ARRAY OF
                  ::= ARRAY OF

qualident         ::= qualifier_list . <identifier>
                  ::= <identifier>
qualifier_list    ::= qualifier_list . qualifier
                  ::= qualifier

Let Tf be the type of a formal parameter f (not an open array) and Ta the type of the corresponding actual parameter a. For variable parameters, Ta must be the same as Tf, or Tf must be a record type and Ta an extension of Tf. For value parameters, a must be assignment compatible with f.

If Tf is an open array, then a must be array compatible with f. The lengths of f are taken from a.

See also the examples in the previous section about procedure declarations.


Contents | Prev | Next | Index

Canterbury Modula-2 for Java  (Last documentation update Feb 8, 2000)
Copyright © 1998 Mill Hill & Canterbury Corporation, Ltd. All rights reserved
Please send any comments or corrections to mhc@webcom.com