• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

4.8 Control Predicates
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Control Predicates
          • fail/0
          • false/0
          • true/0
          • repeat/0
          • !/0
          • ,/2
          • ;/2
          • |/2
          • ->/2
          • *->/2
          • \+/1
    • Packages
Availability:built-in
Source:Condition *-> :Action ; :Else
This construct implements the so-called `soft-cut'. The control is defined as follows: If Condition succeeds at least once, the semantics is the same as (Condition, Action). 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 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.

ClioPatria (version V3.1.1-21-gb8003bb)