In the development of TAQ, built-in functions were created either out of necessity or opportunity. These are presented under the banner of "operations" as they are all implemented as template operands.
Criterion
A criterion is a test for a condition in relation to flow of execution. A criterion is easy to spot because it always] starts with a question mark ?*. There are three criterions that are special functions
- regular expression
- logical status query fact.
- membership set (items enclosed in braces)
The expression "short circuit" is coined for when a logical decision is made before testing for all possibilities. A criterion always triggers a short circuit, It cannot make execution jump to some arbitrary location.
The logic of a criterion can be reversed by placing a colon ':' after the question mark. This can be used to test for something unusual or unexpected.
{}
Set Selection
The set membership criterion is placed to the right of a variable to test if it matches one of a set of literal values.
Braces {}
are used to enclose a comma-delimited literal list with each item being of the same type as the variable
on the left. Here is an example of matching a continent to either North or South America:
american_megacities.taq demonstrates the above set membership operation.
Note that the criterion logic can be reversed to exclude items in the set by placing a colon : character immediately following the question mark.
Fact
A criterion consisting of the fact keyword placed in front of a variable is used to determine whether the variable is empty or otherwise invalid. This feature can be used, for example, to deal gracefully with incomplete or corrupt data.
The fact criterion establishes that a variable:
- is not empty
- is not a number with value NaN (not-a-number)
- in not of type "unknown"
- is not null (a value used to indicate an error has occurred)
For more details, see Fact / unknown.
Object methods
Operand values consist of objects which may be capable of executing functions depending on operand type. Functions are called by appending a full-stop and a method signature with the following format to the operand:
[ variable.]method ([ parameters ])
The parameters are optional and may include expressions along with literals and variables. Note that it is not possible to make a method call on an untyped variable. Also, a method call which returns a value can be placed in an expression.
A few global methods provide utility functions:
Global Method | Return Type | Description |
---|---|---|
reveal | string | Returns content of each parameter |
display | string | Same as reveal() but writes to console too |
random | integer | Returns pseudo-random number |
Requires bound parameter | ||
now | unknown | Returns a timestamp ()java.util.Instant object) |
Variable Declaration
Object methods can be employed in declarations as well as in expressions. This is true for a declaration in a scope as well as in a template. The return type also does not need to be made explicit by using the term keyword. Here is an example of declaring variable "r1" set by the global "random()" method using a bound of 4: