Parameter Passing Mechanisms

M passes the actuallist values to the invoked routine using two parameter-passing mechanisms:

A call-by-value passes a copy of the value of the actuallist expression to the invoked routine by assigning the copy to a formallist variable. If the parameter is a variable, the invoked routine may change that variable. However, because M constructs that variable to hold the copy, it deletes the variable holding the copy when the QUIT restores the prior formallist values. This also means that changes to the variable by the invoked routine do not affect the value of the variable in the invoking routine.

Example:

       SET X=30
       DO SQR(X)
       ZWRITE
       QUIT
       SQR(Z)SET Z=Z*Z
       QUIT
        

Produces:

          X=30
        

A period followed by a name identifies an actualname and causes a call-by-reference.

A call-by-reference passes a pointer to the variable of the invoked routine so operations on the assigned formallist variable also act on the actualname variable. Changes, including KILLs to the formallist variable, immediately have the same affect on the corresponding actualname variable. This means that M passes changes to formallist variables in the invoked routine back to the invoking routine as changes in actualname variables.

Example:

       SET X=30
       DO SQR(.X)
       ZWRITE
       QUIT
       SQR(Z)SET Z=Z*Z
       QUIT
        

Produces:

          X=900