If Condition fails, Else is called. In this case, Then is never executed.
It is allowed, but not recommended to use ->/2 without ;/2 as
( Condition -> Then )If Condition succeeds, any further solutions of Condition are cut and Then is called (as above). If Condition fails, the whole construct fails, which is often considered unintuitive. If this behaviour is really wanted, it can be expressed more clearly by
once(Condition), Then
The more common idiom, where nothing is to be done in the else-case, must be written like this, using true/0:
( Condition -> Then ; true )
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, call should always be enclosed in parentheses:
( Condition -> Then ; Else )
Success: [eclipse]: X = 1, (X == 1 -> write(a); write(b)). a X = 1 yes. [eclipse]: fail->write(not_me); write(me). me yes. [eclipse]: [user]. p(1). p(2). q(1). q(3). r(2). r(3). user compiled 408 bytes in 0.00 seconds yes. [eclipse]: p(X)->q(Y);r(Y). X = 1 Y = 1 More? (;) % p/1 is cut; q/1 isn't. X = 1 Y = 3 yes. [eclipse]: p(3)->q(2);r(2). yes. Fail: [eclipse]: X = 1, (X == 2 -> write(da); write(nyet)). nyet X = _g76 % X is not bound. no. Error: Goal -> write(a); fail. (Error 4). "write(a)" -> true; fail. (Error 5).