Form of Invocation

next up previous contents index
Next: Call by Sharing Up: Invocation Previous: Invocation

Form of Invocation

Invocations have the form:

        <invoc> -> <expr0> "(" [<args>] ")"
<args> -> <expr> ["," <expr>]* ["," <varying_args>] | <varying_args>
<varying_args> -> .. | .. <expr> ["," <expr>]*
The varying_args form allows a variable number of arguments (including none) to be supplied; these arguments together comprise the elements of a sequence that is the last actual argument of the call, and the form is legal only when calling a routine whose last argument is a sequence.

The sequence of activities in performing an invocation is as follows:

  1. The expressions expr (including expr0) are evaluated in an unspecified order.

  2. The expression expr0 must evaluate to a procedure or iterator.

  3. New variables are introduced corresponding to the formal arguments of the routine being invoked (that is, a new environment is created for the invoked routine to execute in).

  4. The objects resulting from evaluating the non-varying-argument exprs are assigned to the corresponding new variables (the formal arguments). The first formal is assigned the first actual, the second formal the second actual, and so on. The type of each expression must be a subtype of the type of the corresponding formal argument.

  5. If the varying_arg form is being used, the last argument of the routine must be a "sequence[T]", and the type of each varying_arg must be a subtype of T. The objects resulting from evaluating the varying_args are used to construct a "sequence[T]", with the first varying_arg being the first element and so on, and the sequence is assigned to the last formal.

  6. Control is transferred to the routine at the start of its body.
The invocation is legal in exactly those situations where there are the same number of actual arguments as formal arguments (after constructing the sequence from the varying_args), and the (implicit) assignments of actuals to formals are legal.

For example, if procedure "p" has signature

proc (int, sequence[int]) returns (sequence[int])
then here are some legal calls of "p":
s: sequence[int]
s := p(0,..3,5,7)  % second argument is a sequence containing elements 3, 5, and 7
s := p(6,..)       % second argument is an empty sequence
s := p(5, s)       % second argument is the sequence s

next up previous contents index
Next: Call by Sharing Up: Invocation Previous: Invocation