6. 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 values ability to be an r-value or l-value. The two qualifiers cannot be combined as they are mutually exclusive.

6.1. Const

A const value is immutable and therefore cannot be an l-value but can be an r-value. For example:

const integer i;

Because a const value is not an l-value, it cannot be passed to a var argument in a procedure.

6.2. Var

A var value is mutable and therefore can be an l-value or r-value. For example:

var integer i;

Note that var is the default Gazprea behaviour and is essentially a no-op unless it is entirely replacing the type.

6.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.