Sporkl Functions

Functions in Sporkl are procedures that are passed zero or more arguments, and may or may not return a value. Functions must either already exist as a predefined function in the function library, or must be defined by the user.

Predefined Functions

Predefined functions are "built-in" Sporkl functions, which do not need to be defined by the user.

For a list of the available predefined functions, click here.

User-defined Functions

The user may define a function by placing a definition of the function anywhere in the program (not necessarily before the point that it is first called), as long as it is in the top level of the program - that is, not located within the body of another function definition, or within the code blocks of any loops, conditionals, etc.

Function definitions have the following form:

function <return type> <function name> ([list of arguments])
   <function body>

<return type> can be any of the basic Sporkl data types except for image, nor can <return type> have array or global qualifiers. If the function does not return anything, <return type> should be set to void.

<function name> must be a unique identifier for the function. It must be destinct from any previously defined functions, declared variables, or reserved words. Function overloading - where two different functions with different argument types or a different number of arguments may have the same name - is not supported for user-defined functions, though a small number of predefined library functions are overloaded.

[list of arguments] is a comma-separated list of zero or more argument variable declarations. These have a similar form as variable declarations in a program statement context, except that the global identifier is not allowed, and the data type can be postfixed with "&", meaning that the argument is to be passed by reference rather than by value. Note that arrays and images are always passed by reference, even when not specified as such. When not specified as such, a compile-time warning is generated.

<function body> is the function code to be executed. When a non-void return value has been specified, the return keyword is used to return a value. If the return type is void, the return keyword, without a return value, may be used to exit the function, otherwise the function will automatically return when the end of the function body code has been reached.

( <-- Back to Sporkl documentation home )