Template-Axiom-Query (TAQ)

Functions

Function libraries can be used to extend TAQ. They are written in Java and can be referenced by class name in the TAQ program or by customizing the application which launches the program. The former approach is used in all the reference examples so they can be launched by a generic application.

Function Declaration

Every function library has a name. A function declaration itself does not identify the library which contains the function. Instead the declaration is placed in a scope with the same name as the library. Thus every library name must comply with TAQ identifier conventions. The declaration starts with the keyword function followed by return type, if applicable, the function name and a parameter signature enclosed in parentheses and containing a comma-delimited list of parameters.

Each parameter is a combination of a basic type followed by a name. The last parameter can have a trailing occurrence pattern. '?' meaning it is optional and '...' means one of more of the same type.

Format

The function declaration format is generalized as follows

function [ type ] name (parameter-signature)

The type is optional. When excluded, it is indicates the function does not return a value or the value can be ignored. A type of unknown indicates the returned object has a type not supported by TAQ. The name is an identifier. Here is an example of function "timestamp" in library "system" declared as returning a string and requiring no parameters

scope system { function string timestamp() }

The declared return type is a request which the function can reject if that type is not supported. In this case, the 'string' type is accepted and the function returns a string formated from a Java runtime Date object.

The library provider Java class can be specified using a "provider" scope property, for example scope system(provider="system.SystemFunctionProvider") {...}

Axiom Return Type

Apart from intrinsic TAQ types, a function return type can also be an archetype of either an axiom list or term list. An Archetype declaration is placed at the start of an TAQ program and has format:

$ template<type> name(term-list)

The type can be axiom or term

and the term-list is one or more comma-delimited typed parameters.

Here is an archetype declaration example for a "service_amount" term template:

$ template<term> service_amount(string service, currency amount)

Request Return Type Example

types2.taq creates an axiom containing terms of different types, the last one containing a function-generated timestamp. Both the value of the timestamp and it's actual Java simple class name are displayed in separate terms

Timestamp=Mon Nov 14 16:37:19 AEDT 2022,
Type=String

The timestamp() function is declared with a return type of string which is implemented as Java type java.lang.String.

function string timestamp()

Change the return type to the default type of unknown, and the timestamp Java simple class name changes to "Date" as the value is implemented as Java type java.util.Date.