aslist
aslist(expr, prototype)
The ASLIST function has the following arguments:
expr
The child expression that is expected to return a list data type value.
prototype
A literal list value that is used as a prototype of the hinted list data type.
This function provides a type hint to the child expression that a list data type value is expected. If the expression does not provide a list valued result having the same data type as the prototype then an error will be raised. The type hint also provides information to the expression compiler about the semantic value that is expected in cases where it is missing, such as an empty list that has no elements.
Many types of list can be hinted and here are a few of the prototype values that can be used:
{'a'} // list of string types {1} // list of integer types {true} // list of boolean types {0.0) // list of number types {{'a'}} // list of list of strings
The data content within the type hint is ignored: only the list type signature is used.
This function is required in situations where the data type of the enclosed expression can not determined by the parser at compile time. This is typically due to an empty list with no elements, or an expression that is evaluated at runtime to determine a column from a data table, such as with the column, eval, tablelist, tablemap or tablerange functions. The type hint provided by the ASLIST function is then used for the semantic analysis required to complete the expression compilation.
No conversion of the data value returned by the child expression is attempted, and if the child data type does not match the hint an error will be generated. For type hinting with data conversion see the list function.
Example 1. An empty list
Empty lists have no elements, so the expression compiler cannot determine the data type. Bare empty lists are not allowed, but the asList type hint can be used to satisfy the requirement for data type identification. For example, an empty list of string values would be represented as:
aslist({},{''})
The content of the second parameter does not matter so long as it is the correct data type. In this example it is an empty string, but it just as well could have been the string 'hello'.
Example 2. Hinting the eval function
The asList function could be used as a wrapper around an eval function to indicate that the evaluation of the internal expression is expected to return a list of integers, as in the following example:
asList(eval('{1}'),{0})
This is surely a trivial example, but in a more realistic example the string being evaluated would have more complex logic. Still, the type is required to compile the expression but cannot be known until the eval function is run.
See the example Table range lookup with a non-literal value in the tablerangefunction for an additional example of how type hints are used.