Language Elements and Reference:xpplrm

Function call and parameter passing Foundation

When a procedure or UDF is declared using the keywords PROCEDUREor FUNCTION, the corresponding section of program code is executed whenever the declared identifier appears in the program followed by parentheses. The parentheses cause the function or procedure to be called and are the "execution operator". Within the parentheses, arguments can be passed to the procedure or function. The arguments are accepted into variables specified in the formal parameter list of the declaration. The parameter list can be specified in the declaration either as a list of identifiers in parentheses or using the keyword PARAMETERS (see the chapter "Arguments and parameters").

When a procedure or UDF is called, the number of arguments may differ from the number of parameters declared. Each function and procedure can be called with no arguments or with a varying number of arguments. When an argument is not specified in the call to a UDF or procedure, the corresponding parameter contains the value NIL. The following program example illustrates this:

PROCEDURE Main 
   LOCAL varA := "AA", varB := "BB" 

   Show()                           // call 1 
   Show(varA)                       // call 2 
   Show("One", varA)                // call 3 
   Show(varA , varB)                // call 4 
   Show( , varA)                    // call 5 
   Show( , )                        // call 6 

RETURN 

************************ 
PROCEDURE Show( c1, c2 ) 
   IF PCount() > 0                  // tests number of parameters 
      ? c1, c2                      // displays parameters received 
   ELSE 
      ? "No parameters received" 
   ENDIF 
RETURN 

The program example results in the following:

Call 1:  No parameters received 
Call 2:  AA NIL 
Call 3:  One AA 
Call 4:  AA BB 
Call 5:  NIL AA 
Call 6:  NIL NIL 

Arguments are specified as a comma separated list enclosed in parentheses in calls to functions or procedures. When no argument is specified after a comma, the value NIL is passed instead of an argument and the matching parameter receives this value. A procedure or function is specified without an argument by including nothing inside the parentheses (for example, Show()). As soon as a single comma appears inside the parentheses, two arguments are passed. For example, Show(,) passes two arguments both containing the value NIL(see the function PCount() in the reference documentation).

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.