|Did you know ...||Search Documentation:|
call(Condition), Action).71Note that the Condition is wrapped in call/1, limiting the scope of the cut (!/0 If Condition does not succeed, the semantics is that of (
\+Condition, Else). In other words, if Condition succeeds at least once, simply behave as the conjunction of
call(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, the semantics is the same as (
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
X=a and X=b, while
succeeds without binding X.