Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Parameter Passing

1990 Version of ANSI Standard

2.5.9 Parameter Passing

Parameter passing is a method of passing information in a controlled manner to and from a subroutine as the result of an exfunc, an exvar, or a Do command with an actuallist.

    actuallist::= ( [ L actual ] )

See section 1 for the definition of L.

    actual::=

. actualname
expr


See 2.3 for the definition of expr.

    actualname::=

name
@ expratom V actualname


See 2.2.1 for the definition of name. See 2.2 for the definition of expratom. See section 1 for the definition of V.

When parameter passing occurs, the formalline designated by the labelref must contain a formallist in which the number of names is greater than or equal to the number of actuals in the actuallist. The correspondence between actual and formallist name is defined such that the first actual in the actuallist corresponds to the first name in the formallist, the second actual corresponds to the second formallist name, etc. Similarly, the correspondence between the parameter list entries, as defined below, and the actual or formallist names is also by position in left-to-right order. If the syntax of actual is .actualname, then it is said that the actual is of call-by-reference format; otherwise, it is said that the actual is of the call-by-value format.

When parameter passing occurs, the following steps are executed:

  1. Process the actuals in left-to-right order to obtain a list of DATA-CELL pointers called the parameter list. The parameter list contains one item per actual. The parameter list is created according to the following rules:
    1. If the actual is call-by-value, then evaluate the expr and create a DATA-CELL with a zero tuple value equal to the result of the evaluation. The pointer to this DATA-CELL is the parameter list item.
    2. If the actual is call-by-reference, search the NAME-TABLE for an entry containing the actuallist name. If an entry is found, the parameter list item is the DATA-CELL pointer in this NAME-TABLE entry. If the actuallist name is not found, create a NAME-TABLE entry containing the name and a pointer to a new (empty) DATA-CELL. This pointer is the parameter list item.
  2. Create the parameter frame on the PROCESS-STACK containing the formallist.
  3. For each name in the formallist, search the NAME-TABLE for an entry containing the name and if the entry exists, copy the NAME-TABLE entry into the parameter frame and delete it from the NAME-TABLE. This step performs an implicit New on the formallist names.
  4. For each item in the parameter list, create a NAME-TABLE entry containing the corresponding formallist name and the parameter list item (DATA-CELL pointer). This step binds the formallist names to their respective actuals.

As a result of these steps, two (or more) NAME-TABLE entries may point to the same DATA-CELL. As long as this common linkage is in effect, a Set or Kill of an lvn with one of the names appears to perform an implicit Set or Kill of an lvn with the other name(s). Note that a Kill does not undo this linkage of multiple names to the same DATA-CELL, although subsequent parameter passing or New commands may.

Execution is then initiated at the first command following the ls of the line specified by the labelref. Execution of the subroutine continues until an eor or a Quit is executed that is not within the scope of a subsequently executed doargument, xargument, exfunc, exvar, or For. In the case of an exfunc or exvar, the subroutine must be terminated by a Quit with an argument.

At the time of the Quit, the formallist names are unbound and the original variable environment is restored. See 2.6.15 for a discussion of the semantics of the Quit operation.

Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Copyright © Standard Documents; 1977-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 Ed de Moel.

This page most recently updated on 13-Sep-2014, 09:20:37.

For comments, contact Ed de Moel (demoel@jacquardsystems.com)