Form of Invocation
Next: Call by Sharing
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:
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.
- The expressions expr (including expr0)
are evaluated in an unspecified order.
- The expression expr0
must evaluate to a procedure or iterator.
- 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).
- The objects resulting from evaluating the non-varying-argument
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.
- 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.
- Control is transferred to the routine at the start of its body.
For example, if procedure "p" has signature
proc (int, sequence[int]) returns (sequence[int])
then here are some legal calls of "p":
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: Call by Sharing