projog

3.41. X,Y - conjunction.

X,Y specifies a conjunction of goals. X,Y succeeds if X succeeds and Y succeeds. If X succeeds and Y fails then an attempt is made to re-satisfy X. If X fails the entire conjunction fails.

Examples

?- true, true.

yes

?- true, fail.

no

?- fail, true.

no

?- fail, fail.

no

?- true, true, true.

yes

?- true, fail, fail.

no

?- fail, true, fail.

no

?- fail, fail, true.

no

?- true, true, fail.

no

?- true, fail, true.

no

?- fail, true, true.

no

?- fail, fail, fail.

no

b :- true.
c :- true.
d :- true.
y :- true.
a :- b,c,d.
x :- y,z.

?- a.

yes

?- x.

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 = a
Z = [q,w,e,r,t,y]

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

yes;
X = 1
Y = b
Z = [q,w,e,r,t,y]

yes;
X = 1
Y = c
Z = [q,w,e,r,t,y]

yes;
X = 2
Y = a
Z = [q,w,e,r,t,y]

yes;
X = 2
Y = b
Z = [q,w,e,r,t,y]

yes;
X = 2
Y = c
Z = [q,w,e,r,t,y]

yes;
X = 3
Y = a
Z = [q,w,e,r,t,y]

yes;
X = 3
Y = b
Z = [q,w,e,r,t,y]

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

yes;
X = 3
Y = c
Z = [q,w,e,r,t,y]

yes

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

yes;
X = 2

yes;
X = 3

yes

?- p2(X), p3(X), p2(X).

no