function-var()
function-var( arg-expr {
, arg-expr} )
The function call has the effect of calling the function function-var. The precise semantics are as follows.
First GAP evaluates the function-var. Usually function-var is a
variable, and GAP does nothing more than taking the value of this
variable. It is allowed though that function-var is a more complex
expression, namely it can for example be a selection of a list element
list-var[int-expr]
, or a selection of a record component
record-var.ident
. In any case GAP tests whether the value is a
function. If it is not, GAP signals an error.
Next GAP checks that the number of actual arguments arg-exprs agrees
with the number of formal arguments as given in the function definition.
If they do not agree GAP signals an error. An exception is the case
when there is exactly one formal argument with the name arg
, in which
case any number of actual arguments is allowed.
Now GAP allocates for each formal argument and for each formal local a new variable. Remember that a variable is a location in a GAP program that points to a value. Thus for each formal argument and for each formal local such a location is allocated.
Next the arguments arg-exprs are evaluated, and the values are assigned
to the newly created variables corresponding to the formal arguments. Of
course the first value is assigned to the new variable corresponding to
the first formal argument, the second value is assigned to the new
variable corresponding to the second formal argument, and so on.
However, GAP does not make any guarantee about the order in which the
arguments are evaluated. They might be evaluated left to right, right to
left, or in any other order, but each argument is evaluated once. An
exception again occurs if the function has only one formal argument with
the name arg
. In this case the values of all the actual arguments are
stored in a list and this list is assigned to the new variable
corresponding to the formal argument arg
.
The new variables corresponding to the formal locals are initially not bound to any value. So trying to evaluate those variables before something has been assigned to them will signal an error.
Now the body of the function, which is a statement, is executed. If the identifier of one of the formal arguments or formal locals appears in the body of the function it refers to the new variable that was allocated for this formal argument or formal local, and evaluates to the value of this variable.
If during the execution of the body of the function a return
statement
with an expression (see Return) is executed, execution of the body is
terminated and the value of the function call is the value of the
expression of the return
. If during the execution of the body a
return
statement without an expression is executed, execution of the
body is terminated and the function call does not produce a value, in
which case we call this call a procedure call (see Procedure Calls).
If the execution of the body completes without execution of a return
statement, the function call again produces no value, and again we talk
about a procedure call.
gap> Fibonacci( 11 ); # a call to the function 'Fibonacci' with actual argument '11' 89
gap> G.operations.RightCosets( G, Intersection( U, V ) );; # a call to the function in 'G.operations.RightCosets' # where the second actual argument is another function call
GAP 3.4.4