Template-Axiom-Query (TAQ)

Names and Namespaces

Modular design is desirable as each module is constructed with artifacts that have a strong affinity for each other. Each artifact name can be made unique by incorporating the module name in it's identity. A module in TAQ is a scope and templates are sub-modules, each with it's own namespace distinct from that of the scope that encloses it,

Beyond defining a namespace, a scope can can be assigned a locale and hold properties set as key-value pairs. The built-in default scope is named "global" and it is implied when scope name is omitted from a reference to an artifact or template.

Identifiers

Identifiers in TAQ follow the Java naming syntax: identifiers begin with an alpha character which is followed by any number of alpha or numeric characters or "_" underscore. You see in all the TAQ examples a naming convention different from Java's camelCase. The convention is intended to make TAQ look different from Java and uses all lower-case names, with underscore character used to separate words eg. surface_area.

An identifier may refer to a scope, template, a term or a declared artifact such as an axiom list. Two and sometimes three identifiers may be combined to form a name using a period "." as a separator. Hence a name can be referred to as being 1-part, 2-part or 3-part according to the number of identifiers it contains.

Addresses

An address is a name containing two identifiers and an at '@' symbol to signify the scope part. A template address leads with the @ followed by scope and template identifiers, for example, "@Asia.megacities" for a template named "megacities" in a scope named "Asia". An artifact address has the scope as the last name preceded by an @, for example, "city_listy@Asia" for an axiom list named "city_list" in a scope named "Asia".The global scope is a special case in that the "global" identifier can be dropped leaving just the @ symbol, for example, "mega_city_list@"

Namespace Scheme

Addresses are not ambiguous while names other than 3-part ones potentially are. The compiler has a strategy for resolving 1 or 2 part names. A 1-part name search starts with the current namespace. If the referenced item is not found, a search is performed in the global scope.

A 2-part name search starts by assuming the first part identifies a template in the current scope. If the referenced item is not found, first part is assumed to be a scope and a search is performed in that scope. From this it follows that good practice is to avoid placing items in the global scope unless it is intentional and preferring to use addresses to reference items belong ing to a different namespace than the current one.

Private Template Scope

A template can have it's own scope for declaring artifacts that are not to be passed to the solution after evaluation. The template scope is optionally placed in a declaration after the template name and before the body. This scope is delimited by braces and the only terms allowed are artifact declarations which do not assign values. This is the template format including the template scope:

template name {
artifact declarations
}
(
terms to create solution
)

Two-part Name Example

continent-scopes.taq demonstrates a template namespace can be alloted from a query declaration. Here the query is selecting from a list of cities, those that belong to a particular continent. The continents in question are Asia and Europe and a scope is created for each one with the same name as the continent

scope Europe
scope Asia

A query for each scope imports an axiom list containing the top 30 largest cities in the world and includes population and continent details. A "megacities" template creates the query solution. It is declared in the global scope but evaluates in the scope nominated by the query.

template megacities (Megacity,Country,Continent ? scope.name )

query<axiom> euro_megacities (mega_city : Europe.megacities)
query<axiom> asia_megacities (mega_city : Asia.megacities)

Note there is nothing ambiguous about the names used in these queries as, in the declaration context, the first part of any 2-part name must be a scope and a 1-part name implies the global scope. continent-scopes2.taq changes the names in the query declarations to addresses. It shows, if preferred, they can used instead of names.

query<axiom> euro_megacities (mega_city@ : @Europe.megacities)