Declarations and assignments
In Veila, declarations are written using a plain arrow. They may be type-annotated as well:
name ← “Livi”
name-with-type: string ← “Rivi”
For ease of typing, <- may be used.
Declarations in Veila are predominantly immutable, but to declare a mutable variable, the name is prefixed with a tilde. When the variable is used in a non-mutating context, the tilde is omitted, but if it’s being mutated, it is prefixed by the tilde again.
Assignment is done with the assignment arrow:
#main
~name ← “Livi”
print-line “My name is ‘name’.” – My name is Livi.
~name ⥳ “Rivi”
print-line “Now I'm ‘name’.” – Now I'm Rivi.
For ease of typing, <~ may be used.
Shadowing
Shadowing names is allowed, but this requires explicit opt-in by prefixing the name with an exclamation mark:
#main
value ← 3
print-line “The value is ‘value’.” – The value is 3.
#do
!value ← 4
print-line “The new value is ‘value’.” – The new value is 4.
print-line “The old value is still ‘value’.” – The old value is still 3.
Shadowing variables are prefixed with ! followed by ~ (e.g. !~value).
The same rule applies to function parameters that shadow names that are already in scope:
value ← 3
print-value ← # (!value)
print-line “The value is ‘value’.”
#main
print-value 4 – The value is 4.