Skip to main content
Version: 1.5.0

Constants

Constants are defined by assigning the value of an expression to a variable (that is, a value name). They are immutable by design, which means that their values cannot be reassigned. Put in another way, they can be assigned once, at their declaration. When defining a constant you can also ascribe a type to it.

Constant declarations are introduced by the keyword const, like so:

const a = 1;
const b : int = a; // Type ascription (a.k.a. annotation)

Note that constants cannot be redefined in the same block scope:

const x = 1;
const x = 2; // Yields an error

However, the following does work:

const d = do {
const x = 1;
{
const x = 2; // No error: a sub-block
return x;
}
};