Functions
A function is a self contained block of code that can be called from multiple points in your program.
Functions are declared using the general syntax:
Function Identifier:ReturnType(Parameters)
Function Statements...
End Function
Functions are called using the syntax Identifier(Parameters).
If ReturnType is omitted, the function defaults to returning an Int.
Parameters is a comma separated list of parameters for the function. The syntax of each parameter is similar to a variable declaration: Identifier:Type. Function parameters may be used inside a function in the same way as local variables.
The Return statement is used to return a value from a function.
Here is an example of a simple function that adds 2 integers and returns their sum:
Function AddInts:Int( x:Int,y:Int )
Return x+y
End Function
This function can then be called by other code:
Print AddInts( 10,20 ) 'prints 30!
Function parameters can be assigned 'default values' using syntax similar to initializing a variable: Identifier:Type=ConstantExpression (note that default values for function parameters must be constant).
Default parameters can then be optionally omitted when the function is called:
Function IncInt:Int( n:Int,p:Int=1 )
Return n+p
End Function
Print IncInt( 1 ) 'Prints 2
Print IncInt( 1,3 ) 'Prints 4