11.1.2 Mode Annotations

The mode annotations are useful to tell whether an argument is input or output or both. They also describe formally the instantiation pattern to the call that makes the call to the built-ins determinate.

The mode annotations in the above example are ‘+’ and ‘-’. Following is a complete description of the mode annotations you will find in the reference pages:

+
Input argument. This argument will be inspected by the predicate, and affects the behavior of the predicate. An exception is raised if the argument isn't of the expected type. Note that an input argument can be an unbound variable in some cases.
-
Output argument. This argument is unified with the output value of the predicate. An output argument is only tested to be of the same type as the possible output value if this is prescribed by the ISO standard, or if such testing is deemed helpful to the user.
?
An argument that could be either input or output. This mode annotation is normally only used for predicates that behave as pure relations and do not type test their arguments.

If the synopsis of a predicate has more than one mode declaration, the first (the topmost) that satisfies the types (of a goal instance) is the one to be applied (to that goal instance).

All built-in predicates of arity zero are determinate (with the exception of repeat/0).

For input arguments, an exception will be raised if the argument isn't of the specified type.

For output arguments, an exception might be raised if the argument is nonvar, and not of the specified type. The generated value of the argument will be of the specified type.


Send feedback on this subject.