Syntax Operators

A knowledge base keeps a list of zero, one or more syntax operators. The syntax operators define how Prolog terms are read and written. The interpreter provides the classical access to operators by the predicate op/3 and current_op/3. These predicates take respectively deliver an operator level, an operator mode and an operator name. If an operator has associativity, it is possible to use the operator multiple times in the same expression without parenthesis. The following operator icons are supported:

Table 6: Operator Modes

 Mode Type Associativity fx prefix No fy prefix Yes xf postfix No yf postfix Yes xfx infix No yfx infix Left xfy infix Right

Example:
```?- [user].
:- op(200, xfy, ++).
append(nil, X, X).
append(X++Y, Z, X++T) :- append(Y, Z, T).
^D
?- append(X, Y, a++b++c++nil).
X = nil,
Y = a++b++c++nil ;
X = a++nil,
Y = b++c++nil
```

In the example above we have defined an infix operator (++)/2 with right associativity. Jekejeke Prolog provides further properties of individual operators. The access of the properties is based on an operator indicator which is one of the terms prefix(O), postfix(O) or infix(O) where O is the operator name. The user operator indicators can be enumerated via the predicate current_oper/1. The operator properties can be accessed and modified via the predicates oper_property/2, set_oper_property/2 and reset_oper_property/2.

```oper    --> "prefix(" name ")"
| "postfix(" name ")"
| "infix(" name ")".

name    --> module ":" name
| atom.
```

A first set of operator properties deals with the visibility of the operator. These are the proper-ties system/0, full_name/1 and private/0. Pretty printing is done by controlling the indentation of operators and the spaces around an operator. Pretty printing is only in effect for terms aka clauses and goals. Arguments are printed in minimizing the number of spaces. Pretty printing is inferred from the meta-predicate declaration and the operator level

The following syntax operator predicates are provided:

op(L, M, N): [ISO 8.14.3]
op(L, M, [N1, â€¦, Nn]): [ISO 8.14.3]
For L <> 0 the predicate (re-)defines the operator N with mode M and level L. For L = 0 the predicate undefines the operator N with mode M.
sys_neutral_oper(I):
If no syntax operator has yet been defined for the syntax operator indicator I, defines a corresponding neutral syntax operator.
current_op(L, M, O): [ISO 8.14.4]
The predicate succeeds for every defined operator O with mode M and level L.
current_oper(I):
The predicate succeeds for each user operator I.
oper_property(I, P):
The predicate succeeds for each property P of each user operator I. The following operator properties are supported:
full_name(I): I is the qualified operator indicator.
nspl: The operator has no space left pretty printing.
nspr: The operator has no space right pretty printing.
level(L): The operator precende is L.
mode(M): The operator icon is M.
set_oper_property(I, P):
The predicate assigns the property P to the operator I.
reset_oper_property(I, P):
The predicate de-assigns the property P from the operator I.

The following syntax operator properties are provided:

sys_alias(A):
The syntax operator property indicates that the operator should be replaced by A during parsing. The property is single valued or can be missing. The property can be changed.
sys_portray(P):
The syntax operator property indicates that the operator should be replaced by P during un-parsing. The property is single valued or can be missing. The property can be changed.