Programmer's Guide to the Zeno Interpreter
Chapter 5. Subprograms
It is almost always necessary to use subprogram modules so that your programs are easy to understand and maintain. There are two distinct types of subprogram modules. A procedure is a statement by itself. A function returns a value for use in expression evaluation.
Subprogram calls
A call to a subprogram has the form:
name( argument{, argument} )
or,
name
if the subprogram has no parameters.
Program execution jumps to the subprogram declaration. The call passes each argument to the subprogram. Upon completion of the statement list in a subprogram's body, program execution returns to the point immediately after the call.
An example:
x := square( 7 )
Arguments and parameters
The arguments used in a subprogram call must be compatible with the parameters defined in a subprogram declaration. Arguments are passed to a subprogram either by value or by reference. Arguments passed by value cannot be changed by the subprogram. This means that a variable used as an argument will have the same value before and after the subprogram call it was used in. When an argument is passed by reference, the address of the argument is given to the subprogram. In this case, a variable used as an argument may have a different value before and after the subprogram call.
|