Availability:built-in
\+
Condition, Else). In other words, if Condition
succeeds at least once, simply behave as the conjunction of
Condition and Action, otherwise execute Else.
The construct is known under the name if/3 in some other Prolog
implementations.
The construct A *->
B, i.e.,
without an
Else branch, is translated as the normal conjunction A,
B.bugThe decompiler
implemented by clause/2
returns this construct as a normal conjunction too.
This construct is rarely used. An example use case is the implementation of optional in sparql. The optional construct should preserve all solutions if the argument succeeds as least once but still succeed otherwise. This is implemented as below.
optional(Goal) :- ( Goal *-> true ; true ).
Now calling e.g., optional(member(X, [a,b]))
has the
solutions
X=a and X=b, while optional(member(X,[]))
succeeds without binding X.