Expressions are constructed using literals, variables and object methods, either singly, or in combination connected by symbolic operators to which precedence applies. TAQ adopts almost all Java's operators and operator precedence. Missing are ""instanceof and ""ternary"". However, the TAQ '?' and ":' operators are used in a way that echoes Hava's ternary operator.
Special Operators
Here are operators specific to TAQ. Note that some operators have a dual use depending on context:
Operator | Context | Description |
---|---|---|
? | axiom term | Blank place holder |
? | template term | Criterion |
?: | template term | Converse criterion |
-> | query | Chain to right |
-> | template term | Select term by name |
Literals
Literals represent values of the supported types. TAQ literals follow Java for strings, numbers and boolean "true" and "false". Character literals are not supported. Also TAQ has unknown for an empty variable declared without being assigned a type and NaN* for ""not a number"".
Any numeric expression that fails, for example divide by zero, results in a value of NaN.
Variables
All variables are operands designed to participate in a template's unification and evaluation cycles. A variable is set either at compilation time meaning it is a literal, or during execution of a query. For every expression operator a special operand called an "Evaluator" is created which facilitates evaluation. Any non-trivial expression therefore ends up as an operand graph with an Evaluator at each node.
A list variable may reference the list itself or a list item, Consider the following axiom list containing 4 high cities that needs to be sorted by elevation
{"denver", 5280}
{"flagstaff", 6970}
{"leadville", 10200}
Note that a list header has been employed to name both of the terms in each list item. The first axiom in the list with city "addis abada"
is referenced by variable high_cities[0]. The right arrow '->
' selects an axiom term by name. Hence
high_cities[0]->altitude
is a variable with value 8000. To iterate through the list, use an incrementing index such as [i++] where
i is an integer initialized to zero.
Declarations
A variable declaration is it's first occurrence, regardless of format. If the variable type is not revealed by the format, for example it is just an identifier, then it will be resolved when the variable is set either by unification or evaluation. In the former case, it's value can be changed to a one of a different type in a subsequent evaluation within the same template.
A variable can be declared in either the scope or body of a template, but assigning a value to it at the same time is only allowed in the body. Advantage can be taken with number types and boolean in that they have default values which mimic the behavior of primitives in Java. Numbers default to zero and boolean to false.
Scope Variables
Scope variables have differences from those declared in a template. The most important is that only formats that reveal the variable type are allowed. Therefore, an identifier, on it's own, is not allowed. There is also no structure in a scope, so terms are not separated using a comma. Scope variables are evaluated just before a query is launched and reset back to their initial state at the conclusion of the query. A template may change the value of a scope variable, but otherwise there is no interaction with template unification/evaluation cycles.
scope-cycles.taq demonstrates scope variable features. It also shows that the initialization of scopes is in the order they are declared. A forward reference to another scope from within a scope will cause an error. Here is the global scope and the other scope declarations
term random = random(1000)
scope one {
scope two {
scope three {