• Reference Guide

Variable Definition

var Type flag name;
var Type flag name = value;
var flag name = value;
This construct creates a variable of the specified type (the parameter Type) and name (the parameter name, which must be an identifier). If a value is appended next to an equal sign, it is an Enki expression providing the initial value of the variable. If it is not specified, the initial value of the type is used.
If an initial value is specified, it is not necessary to specify the variable type explicitly, as it can be inferred from the initial value type.
On contrary to Enki, it is allowed for variables to contain analytic items in Enkidu.
The terminating semicolon is optional.

L-value Variables

When an ampersand (&) is used within the variable definition flags, the variable will not contain a direct value, but rather a reference to a data item containing the value. (That is, the value of the variable will be an l-value – see the chapter Data References.)

Constant Variables

Using the keyword const among the variable definition flags, the variable is made constant – i.e. it is not possible to change its value. This is useful in combination with an l-value – the reference stored in the variable can be used to read the value, but not to modify it.
var String const &item = document.data.customers.0.name;
With this definition, it can be performed:
&item = document.data.customers.1.name;
but not:
item = "Adam";

Non-strict Variables

If a question mark (?) is used in variable definition flags, it makes the variable non-strict. A non-strict variable can contain, besides the declared type, a value of the Error type. This enables to intercept and handle error that occurred during the program execution. For more details, see the chapter on error handling in the Enki language.

Variable Scope

A variable is accessible from the place of its declaration onwards up to the end of the template or end of the block. Every sub-template defined in a structured command constitutes a block. The command constituting blocks are: block, if, for, switch, and while.