• Reference Guide

Compound Values

In Enki, it is possible to manipulate with compound values in the same way as with scalars. Thus, constants of the compound types – structures, arrays, and sequences – can be created. In general, a constant of a compound type is written as a list of comma separated values enclosed in curly brackets. For instance:
{5, 8, 15, 29}
The type of the compound value constructed this way is always a sequence with the element type inferred from the types of the values used. If more than one value types are used, the element type is a union of all of them. Implicit conversions to other compound data types exist for such a type. Thus, it is possible to write:
var Int[2] pair;
pair = {5, 10}
The assignment in the second line automatically converts the compound value to a two-element array, and this value is assigned to the variable pair.
When necessary, the conversion can be enforced with the typecast operator.


A sequence type can be also converted to a structure. In that case, the conversion is performed along to the order of the structure components as they appear in the definition.
Let us consider the structure Person defined with the following components:
Struct(String name
String addr
String city)
Then, the following assignment can be performed:
var Person sender;
sender = {"Jan Novak", "Steinerova 12", "Prague"}
As it can be unclear what the order of the components in the definition is, and as it can possibly change, the names of the components can be specified explicitly by writing the name followed by a colon in front of the value:
sender = {name: "Jan Novak", addr: "Steinerova 12", city: "Prague"}
Compound values constructed this way are still sequences. The names specified are associated with the elements as their names, which can be then used instead of the indexes. The names are also used when the sequence is converted to a structure. If there are some elements without a name in the list, they are assigned in their sequence from the last named one when converting to a structure. Unspecified components are assigned by their initial values (when defining a type in the document section Definitions, the initial value can be explicitly specified.) Therefore, the expression
sender = {addr: "Steinerova 12", "Prague"}
is equivalent to
sender = {name: "", addr: "Steinerova 12", city: "Prague"}

Non-Constant Compound Values

In the very same way, a value that has components specified by a variable or an expression can be constructed. For instance, the code
var Int[2] pair;
pair = {x, 2*y}
is equivalent to
var Int[2] pair;
pair[0] = x;
pair[1] = 2*y