Table of Contents
Sets up templates of alternative contextual tests which can later be referred to by multiple rules or other templates. Templates support the full syntax of contextual tests, including all other new CG-3 features. Best way to document them that I can think of at the moment is to give examples of equivalent constructions.
For example, this construction
TEMPLATE tmpl = 1 (a) LINK 1 B + C LINK 1 D - (e) ; SELECT (tag) IF (T:tmpl) ;
is equivalent to
SELECT (tag) IF (1 (a) LINK 1 B + C LINK 1 D - (e)) ;
But with the introduction of templates, CG-3 also allows alternative tests, so this construction
TEMPLATE tmpl = (1 ASET LINK 1 BSET) OR (-1 BSET LINK -1 ASET) ; SELECT (tag) IF (1 Before LINK T:tmpl LINK 1 After) ;
is equivalent to
# Yes, inline OR is allowed if you () the tests properly SELECT (tag) IF (1 Before LINK (1 ASET LINK 1 BSET) OR (-1 BSET LINK -1 ASET) LINK 1 After) ;
which in turn is equivalent to
SELECT (tag) IF (1 Before LINK 1 ASET LINK 1 BSET LINK 1 After) ; SELECT (tag) IF (1 Before LINK -1 BSET LINK -1 ASET LINK 1 After) ;
For very simple lists of LINK 1 constructs, there is a further simplification:
# Note the use of [] and , instead of () TEMPLATE tmpl = [(a), BSET, CSET - (d)] ;
is equivalent to
TEMPLATE tmpl = 1 (a) LINK 1 BSET LINK 1 CSET - (d) ;
However, the [] construct is not directly allowed in OR constructions, so you cannot write
TEMPLATE tmpl = [a, b, c] OR [e, f, g] ; # invalid
but you can instead write
TEMPLATE tmpl = ([a, b, c]) OR ([e, f, g]) ; # valid
The [] construct can also be linked to and from, so
TEMPLATE tmpl = [a, b, c] LINK 1* d BARRIER h LINK [e, f, g] ;
is equivalent to
TEMPLATE tmpl = 1 a LINK 1 b LINK 1 c LINK 1* d BARRIER h LINK 1 e LINK 1 f LINK 1 g ;
Templates can be used in place of any normal contextual test, and can be both linked to and from, so
TEMPLATE tmpl = 1 (donut) BARRIER (waffle) ; SELECT (tag) IF (1 VSET LINK T:tmpl LINK 1* FSET) ;
is equivalent to
SELECT (tag) IF (1 VSET LINK 1 (donut) BARRIER (waffle) LINK 1* FSET) ;
It is also possible to override the position of a template, which changes their behavior. E.g:
TEMPLATE tmpl = [N, CC, ADJ] ; # ... or ... TEMPLATE tmpl = 1 N LINK 1 CC LINK 1 ADJ ; SELECT (tag) IF (-1 T:tmpl) ;
is equivalent to
SELECT (tag) IF (-1** N LINK 1 CC LINK 1 ADJ) ;
but with a post-condition that the cohorts at the edges of the instantiated template must be at the position given relative to the origin. In this case, a match of the template is only succesful if ADJ is in position -1 to the origin (tag). This behavior is equivalent to how templates worked in Fred Karlsson's CG-1, but with more flexibility.
The post-condition check cannot currently inspect the actual edges of the space that the template touched to instantiate, so it will perform the edge checks on the entry and exit cohorts only. A positive override will require that the leftmost edge matches the position, while negative override will require rightmost edge matches. When linking from overridden tests, a positive link will try to match from the rightmost edge, and negative link from the leftmost.