Note: The behaviour of this predicate changes when it is specified as the first argument of a structure of the form ;/2
, i.e. the "disjunction" predicate. When a ->/2
predicate is the first argument of a ;/2
predicate then the resulting behaviour is a "if/then/else" statement of the form ((if->then);else)
.
Examples
if_then_else_test(1).
if_then_else_test(2).
if_then_else_test(3).
?- 2>1 -> true.
yes
?- 2<1 -> true.
no
?- 2>1 -> fail.
no
?- if_then_else_test(X) -> if_then_else_test(X).
X = 1
yes
?- if_then_else_test(X) -> if_then_else_test(Y).
X = 1
Y = 1
yes;
X = 1
Y = 2
yes;
X = 1
Y = 3
yes
?- true -> X=a ; X=b.
X = a
yes
?- fail -> X=a ; X=b.
X = b
yes
?- (X=a, 1<2) -> Y=b; Y=c.
X = a
Y = b
yes
?- (X=a, 1>2) -> Y=b; Y=c.
X = UNINSTANTIATED VARIABLE
Y = c
yes
?- if_then_else_test(X) -> if_then_else_test(X) ; if_then_else_test(X).
X = 1
yes
?- (if_then_else_test(X), fail) -> if_then_else_test(X) ; if_then_else_test(X).
X = 1
yes;
X = 2
yes;
X = 3
yes
?- if_then_else_test(X) -> if_then_else_test(Y) ; Y=b.
X = 1
Y = 1
yes;
X = 1
Y = 2
yes;
X = 1
Y = 3
yes