next up previous contents index
Next: Tabling Directives Up: Compiler Directives Previous: Compiler Directives   Contents   Index


Mode Declarations

The XSB compiler accepts mode declarations of the form:

:- mode ModeAnnot1,..., ModeAnnotn.

where each ModeAnnot is a mode annotation (a term indicator whose arguments are elements of the set {+,-,#,?}). From Version 1.4.1 on, mode directives are used by the compiler for tabling directives, a use which differs from the standard use of modes in Prolog systems3.4. See Section 3.8.4 for detailed examples.

Mode annotations have the following meaning:

+
This argument is an input to the predicate. In every invocation of the predicate, the argument position must contain a non-variable term. This term may not necessarily be ground, but the predicate is guaranteed not to alter this argument).

:- mode see(+), assert(+).

-
This argument is an output of the predicate. In every invocation of the predicate the argument position will always be a variable (as opposed to the # annotation below). This variable is unified with the value returned by the predicate. We note that Prolog does not enforce the requirement that output arguments should be variables; however, output unification is not very common in practice.

:- mode cputime(-).

#
This argument is either:
?
This argument does not fall into any of the above categories. Typical cases would be the following:
We try to follow these mode annotation conventions throughout this manual.

Finally, we warn the user that mode declarations can be error-prone, and since errors in mode declarations do not show up while running the predicates interactively, unexpected behavior may be witnessed in compiled code, optimized to take modes into account (currently not performed by XSB). However, despite this danger, mode annotations can be a good source of documentation, since they express the programmer's intention of data flow in the program.


next up previous contents index
Next: Tabling Directives Up: Compiler Directives Previous: Compiler Directives   Contents   Index
Luis Fernando P. de Castro 2003-06-27