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
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") {...}
Optional Parameter Example
The next example looks back to gaming.taq, which plays one spin of a poker machine with a fruit theme, By means of the global "random" object method, a Java library utility is used to generate random numbers range from 0 to 3 which is set by a "bound" parameter value of 4. If the system library implemented random(), it would be declared as follows
The parameter specification with a trailing '?' indicates the 'bound' parameter is optional. Without this parameter, the function returns a potentially large unbounded random number.
Archetype Examples
function-service-items.taq demonstrates a function which returns a term list declared as a "service_amount" template archetype. This list contains a "service" term to identify the service and an "amount" term:
scope service {
The function return value is assigned to an axiom