Sfairadora

  • Reference Guide

Sequence, Table

Sequence is a compound type whose instance consists of a variable number of elements of the same type. Individual elements are identified by integer indexes. The index of the first element is 0, the index of the second element is 1, and so on up to n–1 (where n is the number of the sequence elements). Sequence elements may be assigned names. Then, they can be alternatively identified either by indexes or by names. Every element can have one name at most.
In contrast to array, new elements can be inserted into a sequence as required, and thus the sequence size may grow. If you insert an element in the middle of a sequence, the indexes of the subsequent elements are increased by one, but the identity of named elements is preserved. Analogically, you can also remove elements from the sequence.
A sequence whose element is a structure is called a table. A table defined this way corresponds to the concept of tables in standard database systems. Components of the structure that determines the type of the sequence elements represent attributes or columns of the table.
You can impose a condition restricting element values (filter) or element ordering on a sequence, or specify that the values of some table columns (or values of entire elements) must be unique. You can also specify an inserter function and a remover function performing some specific operation when an element is inserted into a sequence or removed from it, respectively.

Filter

A filter defines a condition that must be satisfied in order to insert an element into a sequence.
A filter consists of a set of disjunctive conditions – if any of these conditions is satisfied, the record is acceptable for the sequence.
Every disjunctive condition is either an Enki language function or a list of conjunctive conditions.
If the filter is a function, the returned value is of the Bool type – if the result is TRUE, the record is accepted, while if it is FALSE, it is rejected. The function has no parameters, but it can reference the this object identifying the examined record. Since it is not necessary to explicitly write the name of this object in the Enki language, it is sufficient to write just a<100 instead of this.a<100.
Regarding a list of conjunctive conditions, the conditions must be all satisfied in order to accept the record. Every condition contains a reference determining the column to which it applies. The condition is further specified either by a simple relational operator (equal, greater than, contains …) and a value to be compared with the column value, or by a function that can contain a more complex condition for the column value.
If a function is used, the returned value is of the Bool type – if the result is TRUE, the record is accepted, and if it is FALSE, the record is rejected. The function has one parameter x containing the value of the column whose value is being examined. The specified condition can be therefore independent of the column name.
If a simple relational operator is used, you can specify a value to be compared with the column value – either as a constant or by reference identifying another data item. If the latter is the case, the reference has the object name at the first position followed by the reference within this object. For example, if you need to compare the value with the value in the a column, the reference is this.a.
If any of the conditions is defined by means of a function or a data reference, analytic type supplement info can be specified.

Order

Order is defined by a list of column references (relative to the sequence element) together with the information whether ascending or descending order is required. Only columns of ordered type can be used for ordering (i.e. numeric and string types; compound types are ordered lexicographically based on the ordering of their components). If more than one column is specified for ordering, the sequence is primarily ordered by the first column. If multiple elements in this column have the same value, the order is determined by the column next in succession etc.
If the sequence is ordered, and new elements are being inserted, the index of the element position is not specified – the element’s position is determined automatically.

Unicity

You can specify that some columns in a sequence must not contain duplicate values. Unicity is defined by a list of references to columns whose values must be unique in the sequence. If you specify only one column, every element in the sequence must have a unique value in this column. If you specify n columns, the value of the entire n-tuple must be unique, that is, values in individual columns are not considered separately.
If you require unicity of entire elements of the sequence, use empty reference (period) for column reference.

Inserter Function

An Enki language function called after an element is inserted. The function may perform some initializations or synchronize other data with the new state of the sequence. The function has no parameters, but it can access standard objects; the this object is of particular importance because it represents the inserted data.
The function returns no value (the returned type is None).
By convention, the this identifier need not be explicitly used in the Enki language, therefore, for example, function
this.id = document.data.id_gen++
is identical to
id = document.data.id_gen++

Remover Function

An Enki language function called before an element is removed from a sequence. The function may synchronize other data or remaining elements with the new state of the sequence. The function has no parameters, but it can access standard objects; the this object is of particular importance because it represents the removed data. The function can also access the seq object representing the sequence from which the element is being removed.
If filter, order, unicity, inserting function, or removing function is specified for a sequence, then the sequence is not a free type. A corresponding free type is a sequence with the same element type, but without filter, order, unicity, inserting function, and removing function.

Notation

Seq(TYPE)
or
TYPE[*]
where TYPE is the element type.

See also