Operations on variables
Once you have set variables, you might want to run operations on them. These operations can be adding them (if they are numbers), concatenating them (if they are just strings) or anything else.
Running an operation on a variable is similar to assigning it, except you would use
<
instead of =
:$val1 = 1
$val2 = 2
$val3 < add $val1 $val2
In the code above, we are adding
$val1
and $val2
, therefore $val3
's value is 3. There is a number of operations you can run on variables that are listed in their own category.Operations cannot be run on constants as their value cannot be changed. A workaround to this is, for example:
$constant! = 0
$copy = $constant
$copy < add $val1 $val2
Using functions to change a variable's state is strongly discouraged as it leaves a user with no choice but to change the variable's value. Using variable operations, it is instead possible to get the result of the operation in a different variable, keeping the original one intact.
Last modified 5mo ago