Question

So am being told a specific predicate has to work in +,+ mode. What does that mean in Prolog?

Was it helpful?

Solution

When one wants to give information on a predicate in prolog, those conventions are often used :

arity : predicate/3 means predicate takes 3 arguments.

parameters : predicate(+Element, +List, -Result) means that Element and List should not be free variables and that Result should be a free variable for the predicate to work properly. ? is used when it can be both, @ is mentionned on the above answer but is not really used as much (at least in swi-pl doc) and means that the input will not be bound during the call.

so telling that somepredicate works in +, + mode is a shortcut for telling that :

% somepredicate/2 : somepredicate(+Input1, +Input2)

OTHER TIPS

In order to give you a definite answer you need to tell us more than just +,+. For predicates whose arguments are only atoms, things are well defined: p(+,+) means that the predicate should only be called with both arguments being atoms.

But if we have, say lists, things are more complex. There are two meanings in that case. Consider member/2 which succeeds for member(2,[1,2,3]).

Are the queries member(2,[X]) or member(2,[X|Xs]) now +,+ or not?

The direct interpretation which is also used in ISO Prolog says that (quoting 8.1.2.2 Mode of an argument, from ISO/IEC 13211-1:1995):

  • + the argument shall be instantiated,

In that sense both queries above are +,+.

However, there is another interpretation which implicitly assumes that we have access to the definition of the predicate. This interpretation stems from the mode declarations of DEC-10 Prolog, one of the first Prolog systems. So lets look at member/2:

member(X, [X|_]).
member(X, [_|Xs]) :-
   member(X, Xs).

A mode member(+,+) would now mean that when executing a goal, this mode will hold for all subgoals. That is, member(2,[X]) would be +,+ whereas member(2,[X|Xs]) is not because of its subgoal member(2,Xs).

People do confuse these notions quite frequently. So when you are talking about lists or other compound terms, it helps to ask what is meant.

For more on modes see this answer.

It means that the arguments to the predicate will both be input arguments (though not pure input).

This page has a succint description of all of Prolog's call modes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top