RuLa Functions
Definition
A RuLa function is essentially an expression that performs a task or calculation and then returns one value. The calculation is defined in the function's body. If parameters (or arguments) are required to perform the calculation, they can be passed to the function in parenthesis.
Functions are useful if a task needs to be performed repeatedly at different places in the configuration. Once defined correctly, a function can be used over and over again without having to thinking about the complicated calculation.
Examples
Each function needs a name and a body expression and they can take none as well as one or more parameters.
Without parameters
This function returns whatever is stated in its body, in this case 'Hello everybody'.
This function will return the number 6.
With one parameter
The number that is passed to this function as a parameter is divided by two and then returned as a result. So divide_by_two(30)
would return 15
.
With multiple parameters
In the case of introduce(James, Bond) this would return the string 'My name is Bond but you can call me James".
Within the function's body, other functions can be used, both functions that already exist in Atfinity or the ones that were defined by the user.
This function uses the map function in its body to replace all occurrences of a specific element in that list with a specified replacement. So writing replace_number([8, 5, 8], 8, 0)
would return [0, 5, 0]
.
Last updated