A term is the fundamental unit used to build axioms and terms. As a minimum a term has a name and a value. However, the name can be an empty string meaning the term is anonymous. An axiom term is meant to always have a meaningful value, though there are special values to indicate some error has occurred or the value is blank and may be set at a later stage. A template term is called an "operand" as it is required to participate in unification and evaluation of expressions. However, a template term may just contain a constant value in which case it plays a passive role in template activities.
Type
The most distinguishing characteristic of a term is it's type. This determines behavior such as what operations are permitted, both unary (on it's own) or binary (with another term), what type conversions are permitted and text formats. There is also an "unknown" type for a variable that is declared without specifying it's type.
All operands and solution axioms contain a companion "operator" which governs type behavior. In the case of the axiom, the operator provides support for text formatting in the locale^ to which the term has been assigned.
Basic Types
A basic type is one that can be expressed in text as a literal value. The syntax is taken from Java but not all Java types have been adopted. Note that characters and single quotes have been excluded, but this may change in the future.
Basic Type | Example |
---|---|
string | "Australia" |
integer | 16498 |
double | 11230.9845 |
boolean | true |
decimal | decimal 11230.9845 |
currency | currency "$1234.56" |
The the first four basic types in the above table are self-explanatory. Decimal and currency are based on the Java BigDecimal class which provides operations beyond performing arithmetic such as scale manipulation and rounding. To express a decimal or currency literal requires placing the appropriate keyword in front of the value as shown in the above examples.
A term can be constructed as a basic type variable by declaring the type followed by an identifier, for example,
The term "locale" refers to the combination of language and region that determines conventions for representing numbers and amounts. A default locale is normally applied but a large number of locales are available for selection, if required.
Untyped Variables
An untyped variable is simply an identifier. Examples can be found in. high_cities.taq
Both "city" and "altitude" are untyped variables. However, upon unification, "city" is converted to a string type and altitude to an integer type. This comes from the literals used to set the incoming terms of each city axiom, for example
Identifier Declared as Term Type
An identifier declared as type term constructs a term which is both anonymous and non-private. This allows the value of a variable to be passed to the solution even though the variable itself is private. high_cities3.taq demonstrates this.
{ string city, integer elevation }
(
term city, term elevation
The "high_cities" query returns the following solution to the "high_cities" query, which in the previous two versions displayed a solution using terms named "city" and "altitude"
high_city(denver, 5280)
high_city(flagstaff, 6970)
high_city(leadville, 10200)