Sfairadora

  • Reference Guide

Inferred Sequence

Inferred sequence is a sequence, whose elements have been derived from one or more source sequences. In this respect, the inferred sequence type resembles a query in common database systems.
An example of a very simple inferred sequence is one derived from a single source with a filter applied. Such inferred sequence will contain all elements of the source sequence satisfying the filter. When elements are inserted into the source sequence, removed from it, or modified, the elements of the inferred sequence change accordingly.
An inferred sequence is defined by the following parameters:
●
List of base (source) sequences
●
Element type
●
Filter
●
Order
●
Unicity
●
Inserter function
●
Remover function

List of Base Sequences

Every source (base) sequence is specified by the name of the object in which the source sequence is located and its reference.
If necessary, analytic type supplement info can be supplied, too.
If you define more than one source sequence, the elements of the inferred sequence instance will represent all combinations of the source sequences elements (i.e. a Cartesian product). You can select the desired elements from this set by means of a filter and/or unicity.
In addition to this information, you can also specify that the selected source sequence depends on another source sequence. Dependence of a source sequence on another one means that the dependent sequence is part of an element of the sequence it depends on. Consequently, a different instance of the dependent sequence is used for every element of the master sequence – namely, the instance located in the master sequence element. This logic is used for ungrouping of a dependent sequence.
If you specify that the source sequence depends on another one, the object name must be either src or parent_src. If the object name is src, the source sequence reference is interpreted relatively to the element of the sequence it depends on.
A source sequence may depend only on a sequence previously listed in the list of source sequences. This condition prevents cycles.

Element Type

The type of inferred sequence element is usually a structure. Its components are mostly analytic types establishing a link between the value of the inferred sequence element and the values of the source sequence elements. Especially the use of a forwarded item with the src object name is very common. The element can also contain another inferred sequence. If it has the same source as the parent inferred sequence, it effectively realizes sequence grouping.
The use of other than analytic data types for inferred sequence elements usually has no sense because elements of an inferred sequence dynamically appear and disappear according to the changes made to the source sequences. Consequently, data entered into a non-analytic component would be lost upon the removal of the inferred sequence element.

Filter

A filter defines a condition that must be satisfied in order to accept an element into the inferred sequence.
A filter consists of a set of disjunctive conditions – if any one 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, and if it is FALSE, the record 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.
If the filter is a list of conjunctive conditions, the conditions must all be satisfied in order to accept the record. Every condition contains a reference identifying the column to which it applies. It 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; if it is FALSE, the record is rejected. The function has one parameter x containing the value of the column whose values are being evaluated. 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 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.

Unicity

You can specify that some columns in the inferred sequence instance 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

In order to insert an element into an inferred sequence, the element must be, in fact, inserted into one of the source sequences. In simple situations, Sfairadora is able to decide itself what data should be inserted into which source sequences. However, this automatic method may not be satisfactory in more complex situations. It is therefore possible to specify an inserter function, whose task is to insert adequate data into relevant source sequences in reaction to the insertion of an element into the inferred sequence.
The function has the following parameters:
♦Int index – required index within the inferred sequence identifying the position at which the new element is to be inserted; or –1 if the index has not been specified.
♦ All source sequences not depending on other source sequences. The name of every of these parameters can be specified in the source sequence definition. If it is not specified this way, basen is used, where n denotes the sequential number of the source sequence starting from 1. Only non-dependent source sequences are included in the numbering; source sequences with explicit parameter names are included in the numbering (i.e. their numbers are skipped). The parameters are passed as l-values, so elements may be thus inserted into the sequences.
In addition, the following objects are available to the function:
♦this – the data to be inserted into the inferred sequence.
♦seq – inferred sequence into which the data is being inserted.
The function is specified in the Enki language. It returns no value (the returned type is None), but it may return an error (Error type) if the element cannot be inserted. In this situation, the insertion of an element into the source sequence fails, too.
By convention, the this identifier need not be explicitly used in the Enki language, therefore, for example, this.a is identical to a.

Remover Functions

If you need to remove an element from an inferred sequence, an element must be removed from one (or more) source sequence. In order to actually remove an element from an inferred sequence, it is enough to remove the source element from one of the source sequences. You can specify in the source sequence definition whether the element of the respective source sequence should be removed when an element is removed from the inferred sequence. By default, the source elements of the removed element are removed from all source sequences for which element removal is permitted. If no source sequence permits element removal, and no remover function is defined, the attempt to remove the element fails.
Should this standard procedure of element removal be insufficient, you can define a remover function that decides what data from which source sequences should be removed or otherwise modified so that the result is the removal of the element from the inferred sequence.
The function has the following parameters:
♦ All source sequences. The name of the parameter can be specified in the source sequence definition. If it is not specified this way, basen is used, where n denotes the sequential number of the source sequence starting from 1. Source sequences with explicit parameter names are also included in the numbering. The parameters are passed as l-value, so elements may be thus removed from the sequences.
♦ Indexes of the respective source element for all source sequences. Every parameter’s name is identical to the name of the respective parameter passing the sequence as described above, however, it has an _idx suffix. Hence, if the sequence name is base1, the name of the respective source element index is base1_idx.
In addition, the following objects are available to the function:
♦this – element to be removed.
♦seq – inferred sequence from which data is being removed.
The function is specified in the Enki language. The function returns no value (the returned type is None), but it may return an error (Error type) if the element cannot be removed. I this situation, the removal of an element from the source sequence fails, too.