Reputation: 5549
In user mode in SWI-Prolog I define a function as follows:
|: test1(+X,+Y) :- X >= 0, X =:= Y.
And now in query mode:
?- test1(1, 1).
false.
I was expecting this to return "true" since 1 is greater than 0 and 1 is equal to 1.
So where did I go wrong?
Upvotes: 1
Views: 284
Reputation: 7184
This is what you want instead:
test1(X,Y) :- X >= 0, X =:= Y.
And then:
?- test1(1, 1).
true.
Adding +, - and ? in front of predicate arguments is not part of Prolog. It is just a convention for documenting how predicates should be used.
Here is what the GNU-prolog documentation has to say:
The mode specifies whether or not the argument must be instantiated when the built-in predicate is called. The mode is encoded with a symbol just before the type. Possible modes are:
- +: the argument must be instantiated.
- -: the argument must be a variable (will be instantiated if the built-in predicate succeeds).
- ?: the argument can be instantiated or a variable.
In actual code, you should not prefix arguments with a +.
Upvotes: 5