Variables - Manhunter07/MFL GitHub Wiki

Variables are, similarly to constants, named placeholders for values. Unlike those however, variables can be overwritten and are therefore parrtially stateful.

Declaration

Initialization

By default, variables will be initialized with the value provided by them. If a variable is declared without an explicit value after the equality sign, the compiler initializes it with an empty default-value for a data type. If nothing is specified, this is the null type, resulting in the variable being initialized with Null. Otherwise, dependent on the InitialType setting, the value will be either 0, "", [] or {}.

As an example, we can declare a variable with an initial value of an empty array this way:

opt InitialType = StringType
var NewString

NewString \returns ""\

This behaviour is equivalent to an explicit declaration like:

var NewString = New(@String) \resulting in ""\

Usability

Variables in functional programming

The concept a re-usable named value that is capable of changing does not go well along with strict functional programming paradigms. However, it is generally unclear whether or not this is actually the case if they behave stateless and immutable from inside a function or from outside a package. If you desire to have a purely functional experience without any changable values, you are not supposed to use them. MFL weakens this slightly in favour of having a way to store function results temporarily, but when accessed from inside a function or from outside the package they are declared in, variables behave as constants: There is no way to change their value from either inside any function, or to overwrite them from outside the current namespace.