Special Predicates

It is possible to register predicates and evaluable functions as special built-ins via the built-in special/3. A predicate indicator, the service class and the service number has to be specified. While registering the Prolog interpreter will automatically create an instance of the service class with the given service number parameter.

Syntax:
directive   --> "special(" indicator "," module "," integer ")".

Example:
:- special(foo/1, 'FooAPI', 7).    % is a special predicate directive.

An evaluable function f/n is identified by the predicate property sys_arithmetic/0 and a predi-cate indicator f/n+1. To ease the end-user the Prolog system automatically implements for each predicate bridging to an evaluable function, and for each evaluable function tunnelling to a predicate.

Bridging, predicate as evaluable function:
X is p(Y1,..,Yn) :- 
Z1 is Y1, .., Zn is Yn, p(Z1, .., Zn, X), !.
_ is p(_,..,_):-
throw(error(evaluation_error(partial_function),_)).

Tunnelling, evaluable function as predicate:
f(Y1, .., Yn, X) :- 
X is f(Y1,..,Yn).

During bridging the arguments are evaluated and then the corresponding predicate is called with an additional last argument for the result. If the corresponding predicate succeeds its choice points are removed. If the predicate fails or if the result is not a value, then an error is issued.

The bridging is further controlled by the virtual property of a predicate. If a predicate has this property the first argument Y1 gets special treatment. During bridging this argument will not be evaluated. This is useful for predicates that pass as the first argument the receiver object. The directive virtual/1 can be used to set the virtual property of a predicate.

The following special predicate predicates are provided:

special(I, C, K):
Succeeds with registering the predicate indicator I as a special builtin that calls an instance of the service class C with function index K.
virtual P, ..:
The predicate sets the predicate P to virtual.

The following predicate properties for special predicates are provided:

virtual:
The property indicates that the predicate has the virtual property. The property is single valued and can be missing. The property can be missing. The property can be modified for clause defined predicates. The property cannot be modified for special or foreign predicates.
sys_arithmetic:
The service class implements the predicate via the internal evaluable functions API. The property can be missing. The property cannot be modified.

Comments