+body_term -> +body_term ; +body_term [ISO]

The if-then-else expression is alternative implication in Prolog. If the condition succeeds the choice points are cut and the 'Then' part is executed, the 'Else' part is ignored. If the condition fails the 'Else' part is executed and the 'Then' part is ignored.

The implcation of the cut is that the If-condition cannot be redone while failing!

arrow.gif (1632 bytes) It is necessary to enclose the entire if-then-else expression with parenthesis because the conjunction operator (the AND operator) binds stronger than the disjunction operator (the OR operator).

see also: always/2 call/1 catch/2 catch/3 fail/0 halt/0 halt/1 if-then/2 once/1 repeat/0 throw/1 true/0

Examples  
((X = 0) ->
    (Y = 1)
    ;
    (Y=2)).
succeeds with X=0 and Y=1
((X=1, X = 0) ->
    (Y = 1)
    ;
    (Y=2)).
succeeds with X=1 and Y=2

 

 

info@trinc-prolog.com