defining functions
define proc <name_1> <name_2> <name_3>
proc <name><statement>
endproc
proc <name> ( <arg0> , <arg1> , <arg2> , <argN> )<statement>
endproc
Use the return statement to return a result from a function. The return statement can also be used without a value to cause a procedure to return without a result.Functions can be declared with or without a formal parameter list. If a formal paramter list is defined then the parameters will be accessable via the names specified in the list. Without a formal paramter list or where the number of actual parameters exceeds the number of formal paramter, the parameter operator can be used to access the actual paramters by position.
Function paramters can be access in one of to ways
- by position
e.g.proc fredexample using variable parameter lists- // using the parameter operator '@'
- // to access the first 3 paramters
- return @0 + @1 + @2
endproc
- by name
e.g.proc fred(a, b, c)- // using the names of each parameter
- // to access the first 3 paramters
- return a + b + c
endprocto determine the number of actual paramters passed during a function call
use the argcnt() functioninvoking functions
func()func(a, b)
invoking indirect functions
foo = "fred"(foo)()
(foo)(x, y)
N.B.
paramters are passed by reference not by value
results are passed by valuecall by value must be done exlicitly as:
func(value(x), value(y))returning results from functions and methods
return valsee alsogenerators
methods
modules
external functions