Contents | Prev | Next | Index


Formal Parameters

Formal parameters are identifiers declared in the formal parameter list of a procedure or function. Each formal parameter corresponds to an actual parameter as specified in the procedure or function call. This correspondence between formal and actual parameters is established during the 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.

This compiler also supports the concept of constant parameters. These are for the procedure or function like local variables whose values are not expected to change. Actual parameters are passed to them like value parameters.

Variable parameters may be untyped parameters. They don't have a declared formal type and are hence compatible with any actual parameter.Within the procedure or function they are typeless. Untyped parameters should be regarded as a low-level feature and are usually being dealt with inside an INLINE standard procedure call.

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.

Because of Java restrictions, any changes to a formal variable parameter of a basic type inside a procedure or function won't be reflected to the actual parameter variable outside the procedure until completetion of the procedure execution.

formal_parameters ::= ( fp_section_list )             
fp_section_list   ::= fp_section_list ; fp_section    
                  ::= fp_section                      
fp_section        ::= VAR ident_list : formal_type    
                  ::= ident_list : formal_type        
                  ::= CONST ident_list : formal_type  
                  ::= VAR ident_list                  
formal_type       ::= qualident                       
                  ::= open_array qualident            
                  ::= open_array tvarrec              
                  ::= STRING                          
                  ::= open_array STRING               
                  ::= FILE                            
                  ::= open_array FILE                 
open_array        ::= ARRAY OF                        
tvarrec           ::= CONST                           

func_parameters   ::= : result_type                    
                  ::= ( fp_section_list ) : result_type
result_type       ::= qualident                        
                  ::= STRING                           

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 class type and Ta the same as Tf, or it must be a subclass of Tf. For value parameters, a must be assignment compatible with f.

If Tf is an open array, then the elements of a must be the same as those of  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 Pascal for JVM  (Last documentation update Sep 02, 2004)
Copyright © 1999-2004 J.Neuhoff - mhccorp.com  . All rights reserved.
Please send any comments or corrections to neuhoff@mhccorp.com