Functions

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

to determine the number of actual paramters passed during a function call
use the argcnt() function

invoking functions

func()

func(a,  b)

invoking indirect functions

foo   =   "fred"

(foo)()

(foo)(x,  y)

more complex example of using indirect functions

N.B.
paramters are passed by reference not by value
results are passed by value

call by value must be done exlicitly as:

func(value(x),  value(y))

returning results from functions and methods

return   val
see also
generators
methods
modules
external functions