Functions
Defining functions
Functions are declared with the function keyword:
Parameters
Parameters are listed with their types:
Multiple parameters are separated by commas. Each parameter must have a type annotation.
Return values
To return a value, specify the return type after the parameter list and use return:
Functions without a return type implicitly return nil.
A bare return (with no value) is also valid and returns nil:
function maybeReturn(bool condition) {
if (condition) {
return
}
console.println("condition was false")
}
Calling functions
The number of arguments must match the number of parameters exactly.
The main function
When running a .ccl file, CColon looks for a function named main and calls it automatically. This is the entry point for every program:
Functions defined outside of main are available globally and can be called from main or from each other.
Recursion
Functions can call themselves:
There is no explicit recursion depth limit beyond available stack space.
Functions as values
Functions are stored as global values. You can pass them around and call them indirectly: