[ Control | The ECLiPSe Built-In Predicates | Reference Manual | Alphabetic Index ]

+Condition *-> +Then ; +Else

Soft-cut-conditional construct - succeeds if Then succeeds for some solution of Condition, or if Condition fails and Else succeeds
Condition
Atom or compound term.
Then
Atom or compound term.
Else
Atom or compound term.

Description

This construct is similar to the standard conditional construct

   	Condition -> Then ; Else
   
except that it does not discard alternative solutions to Condition. This means that, on backtracking, alternative solutions to Condition are found, and the Then branch will be executed for each solution of the Condition (rather than just the first one).

This functionality is sometimes referred to as 'soft cut'. A soft cut is a cut that discards an alternative which is not the chronologically most recent one (the Else-alternative is older than the alternatives within Condition).

The operational semantics is as follows: if Condition succeeds, Then is executed, and on backtracking subsequent solutions of Condition and Then are returned, but Else is never executed. Only if Condition has no solutions at all, Else is executed.

Although it is allowed to use *->/2 without ;/2, this is of little use since (Condition *-> Then) is the same as the simple conjunction (Condition , Then).

Also note that Condition must not contain a !/0. If a !/0 appears in Then or Else, it cuts through the whole construct.

Since *->/2 and ;/2 have a lower precedence than ,/2, the whole construct should always be enclosed in parentheses:

    ( Condition *->
        Then
    ;
        Else
    )
    

Modules

This predicate is sensitive to its module context (tool predicate, see @/1).

Fail Conditions

Fails if Then fails for all solutions of Condition, or if Condition and Else both fail

Resatisfiable

Resatisfiable if Condition or Then are resatisfiable, or Condition is not satisfiable and Else is resatisfiable

Exceptions

(4) instantiation fault
One of the arguments is not instantiated.
(5) type error
One of the arguments is neither an atom nor a compound term.

Examples

	?- ( member(X,[1,2,3]) *-> writeln(then(X)) ; writeln(else(X)) ).
	then(1)
	X = 1
	Yes (0.00s cpu, solution 1, maybe more) ? ;
	then(2)
	X = 2
	Yes (0.00s cpu, solution 2, maybe more) ? ;
	then(3)
	X = 3
	Yes (0.00s cpu, solution 3)


	?- X=4, ( member(X,[1,2,3]) *-> writeln(then(X)) ; writeln(else(X)) ).
	else(4)
	Yes (0.00s cpu)

	?- ( member(X,[1,2]) *-> member(Y,[a,b]) ; member(Y,[c,d]) ).
	X = 1
	Y = a
	Yes (0.00s cpu, solution 1, maybe more)
	X = 1
	Y = b
	Yes (0.02s cpu, solution 2, maybe more)
	X = 2
	Y = a
	Yes (0.02s cpu, solution 3, maybe more)
	X = 2
	Y = b
	Yes (0.03s cpu, solution 4)

See Also

-> / 2, ; / 2, ! / 0