Global variables (i.e. variables declared at top-level) are not supported in NPL. However, NPL allows immutable constants to be declared at top-level.
The constant declarations look like variable declarations, but are prefixed with the
const keyword. Just like for
variables, types of constants can be inferred. Therefore, the declaration of the type is not required.
In the following example, both declarations of a
Text constant are valid.
const foo = "foo"; const bar: Text = "bar";
Constants can be used at any place where variables can be used.
Constants can only be declared for simple types:
Party. Default values for
complex types can be created using functions, e.g.
function shortList() -> listOf(1);