• Reference Guide

Type Conversions

Values of a particular data type often need to be converted to another data type. This is achieved by conversions defined for related types. For example, if integer value of 5 is converted to real number type, the resulting value is 5.0. Conversions are either weak or strong depending on their purpose.

Weak Conversions

The purpose of weak conversions is to enable automatic conversion of a value of a particular type to another type in situations where the correspondence between the values is unambiguous and is perceived as identity. An example of a weak conversion is the conversion of an integer to a real number. On the contrary, weak conversion from a real number to an integer is possible only if the source value is a true integer. Weak conversions are automatically chained: if there exists a weak conversion from type A to type B and from type B to type C, and a weak conversion from A to C is required, intermediate conversion to B is automatically performed too.
Weak conversions are used mainly in Enki language expressions, when a type conversion is not explicitly enforced. Its purpose is to make similar types interchangeable, but only to the extent that unintentional errors do not occur as a result of automatically performed conversions.

Strong Conversions

By contrast, strong conversions are designed to preserve source data to the greatest possible extent. They are applied when the type of a data item in the document is changed (i.e. change of column type in a table) or when conversion is explicitly requested in an Enki language expression. Strong conversions are not automatically chained, however, they can chain with weak conversions. For example, if strong conversion from A to C is required, and no such conversion exists while there exists a weak conversion from type A to type B and a strong conversion from type B to type C, the strong conversion will be composed of the two elementary conversions.
It can be concluded that both conversion types are intended to prevent loss of data. However, this is realized in different ways by the two types. Weak conversions prevent undesired loss of data by not performing the conversion automatically when some source data cannot be included in the result. On the other hand, strong conversions are not performed automatically, but only upon request, and they convert all data that can be converted even though only partial conversion is achieved (e.g. when a formatted string is converted to an unformatted string, characters are converted whereas formats are lost; or when a real number is converted to an integer, the number is rounded to the nearest integer, and consequently decimal precision can be lost).
If no direct conversion exists for compound types, they are converted component by component so that components of the same name or components with the same index are assigned.
If type B is created by naming type A, there is automatically a weak conversion from B to A and a strong conversion from A to B.