projog

3.42. X;Y - disjunction.

X;Y specifies a disjunction of goals. X;Y succeeds if either X succeeds or Y succeeds. If X fails then an attempt is made to satisfy Y. If Y fails the entire disjunction fails.

Note: The behaviour of this predicate changes when its first argument is of the form ->/2, i.e. the "if/then" 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

?- true; true.

yes;

yes

?- true; fail.

yes;

no

?- fail; true.

yes

?- fail; fail.

no

?- true; true; true.

yes;

yes;

yes

?- true; fail; fail.

yes;

no

?- fail; true; fail.

yes;

no

?- fail; fail; true.

yes

?- true; true; fail.

yes;

yes;

no

?- true; fail; true.

yes;

yes

?- fail; true; true.

yes;

yes

?- fail; fail; fail.

no

a :- true.
b :- true.
c :- true.
d :- true.

?- a;b;c.

yes;

yes;

yes

?- a;b;z.

yes;

yes;

no

?- a;y;c.

yes;

yes

?- a;y;z.

yes;

no

?- x;b;c.

yes;

yes

?- x;b;z.

yes;

no

?- x;y;c.

yes

?- x;y;z.

no

p2(1) :- true.
p2(2) :- true.
p2(3) :- true.

p3(a) :- true.
p3(b) :- true.
p3(c) :- true.

p4(1, b, [a,b,c]) :- true.
p4(3, c, [1,2,3]) :- true.
p4(X, Y, [q,w,e,r,t,y]) :- true.

p1(X, Y, Z) :- p2(X); p3(Y); p4(X,Y,Z).

?- p1(X, Y, Z).
X = 1
Y = UNINSTANTIATED VARIABLE
Z = UNINSTANTIATED VARIABLE

yes;
X = 2
Y = UNINSTANTIATED VARIABLE
Z = UNINSTANTIATED VARIABLE

yes;
X = 3
Y = UNINSTANTIATED VARIABLE
Z = UNINSTANTIATED VARIABLE

yes;
X = UNINSTANTIATED VARIABLE
Y = a
Z = UNINSTANTIATED VARIABLE

yes;
X = UNINSTANTIATED VARIABLE
Y = b
Z = UNINSTANTIATED VARIABLE

yes;
X = UNINSTANTIATED VARIABLE
Y = c
Z = UNINSTANTIATED VARIABLE

yes;
X = 1
Y = b
Z = [a,b,c]

yes;
X = 3
Y = c
Z = [1,2,3]

yes;
X = UNINSTANTIATED VARIABLE
Y = UNINSTANTIATED VARIABLE
Z = [q,w,e,r,t,y]

yes

?- p2(X); p2(X); p2(X).
X = 1

yes;
X = 2

yes;
X = 3

yes;
X = 1

yes;
X = 2

yes;
X = 3

yes;
X = 1

yes;
X = 2

yes;
X = 3

yes

?- p2(X); p3(X); p2(X).
X = 1

yes;
X = 2

yes;
X = 3

yes;
X = a

yes;
X = b

yes;
X = c

yes;
X = 1

yes;
X = 2

yes;
X = 3

yes

?- X=12; X=27; X=56.
X = 12

yes;
X = 27

yes;
X = 56

yes

?- p2(X); X=12; p3(X); X=27; p2(X).
X = 1

yes;
X = 2

yes;
X = 3

yes;
X = 12

yes;
X = a

yes;
X = b

yes;
X = c

yes;
X = 27

yes;
X = 1

yes;
X = 2

yes;
X = 3

yes