-
Notifications
You must be signed in to change notification settings - Fork 2
Function calls
When a function has been declared, calling such is done by its identifier, similar as with any other declared object. If one or more argument(s) shall be passed to the call, they can be passed separated by commas within parentheses. If a function does not require arguments for call, parentheses are optional. Arguments are stored in memory per-[parameter](Function parameters) for each call.
Error
Error()
Error("Failed")
Sin(1)
Cos(4 * (Pi + 0.2))
Index("c", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr")
Functions can be called anywhere where dynamic values are allowed. This includes other function bodies, the body of the same function (recursion), parameter fallback values of other functions or initial values of variables for example.
You can explicitely name arguments as well, allowing to leave out non-trailing optional arguments or to change their order. After a named argument there cannot follow any ordered arguments. Named arguments cannot be passed to variable argument parameters.
function Foo(A, B = 5, C) = \...\
Foo(1, 2, 3) \Calls Foo with A=1, B=2, C=3\
Foo(1, C = 6) \Calls Foo with A=1, B=5, C=6\
Foo(C = 6, A = 4) \Calls Foo with A=4, B=5, C=6\
Main article: Spreading
You can spread structured values uppon multiple parameters when calling a function. This is called spreading and allows the passing of an undefined amount of arguments to a function. Supported values are records and arrays. Strings can be spreaded, too, but are implicitely converted to an array of characters and their characters then passed as arguments.
Spreading arrays uppon function parameters defines the arguments by their corresponding array index, whereas when spreading a record, the field names are used as target parameter names and their values as arguments. If the length of an array is below the minimum or above the maxumum argument count of the function, an exception is raised. The same goes for the case of the record field names not matching the parameter names.
If a function is called recursively by itself, each call contains an own set of arguments that can be accessed only by the current call instance, equally as when calling a different function inside a function's body. It is your job to prevent a function from being called by itself with identical arguments. In an emergency, you can prevent infinity calls by setting the MaxCallDepth option to something less.
Texts, images and code samples on this page are available under MPL 2.0 license