Reputation: 421
I've searched for an explanation to this but haven't found one. What do the question mark, plus sign, and minus sign that sometimes precede variable names in the description of a Prolog predicate mean?
Example:
predicate(?Variable1,+Variable2,-Variable3)
Upvotes: 24
Views: 9738
Reputation: 41625
?
means: This variable can be either instantiated or not. Both ways are possible.+
means: This variable is an input to the predicate. As such it must be instantiated.-
means: This variable is an output to the predicate. It is usually non-instantiated, but may be if you want to check for a specific "return value".Source: Chapter 4 of the SWI Prolog documentation.
Upvotes: 36
Reputation:
+
means that Variable2
is expected to be bound (to a term, or perhaps just some variable) -- you can think of this as input to predicate/3
, which the predicate won't attempt to modify in execution.
-
means that Variable3
is expected to be bound by predicate/3
in it's execution -- you can think of this as output from predicate/3
. This doesn't mean it can't be bound, however, particularly if you know what to expect and are checking for success, but predicate/3
is described as potentially binding (unifying) Variable3
to something.
?
means that Variable1
can be either be bound (+
, input) or not (-
, output) - predicate/3
should deal with both cases, if it accepts either.
Upvotes: 5