Functions

SPL functions are similar to native functions: they can take parameters, return a value or return void, are defined in a namespace, and not nested in anything else.

Functions are called from expressions, which can occur in many places in an SPL program. There are two kinds of functions. Non-native functions are written in SPL, and native functions are written in C++ or Java. Both kinds of functions can be invoked from SPL with the same syntax. The caller is oblivious to the implementation language.

Functions can be passed as parameters to operators because an operator invocation is fully resolved at compile time. But SPL does not permit passing functions to other functions or storing them in variables because it makes code harder to understand for the user, and it is harder to optimize indirect invocations in a static compiler. SPL provides neither first-class functions nor higher-order functions.

Functions can be overloaded. In other words, there can be multiple functions with the same name in the same scope, when they have different parameter signatures. For example, the library has multiple definitions for the rstring formatNumber function, two of which are formatNumber(int64 value) and formatNumber(float64 value). While SPL permits overloading on parameter types, it forbids overloading on return value types. For example, declaring both int32 f() and rstring f() in the same scope results in a compile-time error.