7. Type Qualifiers
Gazprea has two type qualifiers: const and
var. These qualifers can prefix a type to specify its mutability or
entirely replace the type to request that it be inferred. Mutability
refers to a value’s ability to be an rvalue or lvalue.
The two qualifiers cannot be combined as they are mutually exclusive.
7.1. Const
A const value is immutable and therefore cannot be an lvalue but
can be an rvalue. For example:
const integer i;
Because a const value is not an lvalue, it cannot be passed to a
var argument in a procedure.
Note that const is the default Gazprea behaviour and is essentially a
no-op unless it is entirely replacing the type.
7.2. Var
A var value is mutable and therefore can be an lvalue or rvalue.
For example:
var integer i;
The compiler should raise an error if an attempt is made to modify a variable
that is not explicitly declared var.
7.3. Type Inference Using Qualifiers
Type qualifiers may be used in place of a type, in which case the real type must be inferred. A variable declared in this manner must be immediately initialised to enable inference. For example:
var i = 1; // integer
const i = 1; // integer
var r = 1.0; // real
const c = 'a'; // character
var t = (1, 2, 'a', [1, 2, 3]); // tuple(integer, integer, character, integer[3])
const v = ['a', 'b', 'c', 'd']; // character[4]
See Type Inference for a larger description of type inference, this section only
provides the syntax for inference using const and var.