Variables & constants
Variables and constants can be used to store values. They act sort of like drawers, where you can put different things and get them out again when needed.
Variables
Variables can store a value. They always start with a lowercase letter and are created directly with the first assignment.
a = 4
When assigning, the type of the variable is also specified. So it is generally not possible to assign a different object type to the same variable later. However, this can be allowed, but more about this later.
When using the text terminal, the value is immediately forgotten. But we can hang several commands with a ';' behind each other.
a = 4; a.print
Here the variable 'a' is assigned the value (or object) 4. This will then be output in the next command. Now we can do calculations and store them in the variable.
a = 3 * ( 9 + 20 ); a.print
Here also brackets can be used. Let's take a second variable to it:
a = 3; b = 9 + 20; ( a * b ).print
Constants
While a variable can always be assigned new objects, constants (as the name suggests) are constant. That means, a value is passed, which cannot be changed afterwards.
ABC = 5
Attention!
Whether variable or constant, regardless of case, a name may only be used once (for clarity).
Simultaneous use of "abc" and "ABC" is thus not possible.
If one would now assign a value to the constant "ABC" again, one would receive an error message.
Since we only assigned a value once for the variables in the previous examples, we could also replace them with constants:
A = 4; A.print
A = 3 * ( 9 + 20 ); A.print
A = 3; B = 9 + 20; ( A * B ).print
Already assigned
The following names are already assigned and may be used neither for variables, nor for constants:
- app
- cur
- each
- false
- func
- it
- jmo
- nil
- loop
- this
- true