The predicate call
makes it possible to call goals that are determined at runtime rather than when a program is written. call(X)
succeeds if the goal represented by the term X
succeeds. call(X)
fails if the goal represented by the term X
fails. An attempt is made to retry the goal during backtracking.
Projog also supports overloaded versions of call
for which subsequent arguments are appended to the argument list of the goal represented by the first argument.
Examples
?- call(true).
yes
?- call(fail).
no
?- X = true, call(X).
X = true
yes
?- X = fail, call(X).
no
test(a).
test(b).
test(c).
?- X = test(Y), call(X).
X = test(a)
Y = a
yes;
X = test(b)
Y = b
yes;
X = test(c)
Y = c
yes
testCall(X) :- call(X).
?- testCall(fail).
no
?- testCall(true).
yes
?- testCall((true ; true)).
yes;
yes
Note: "time" is a synonym for "call".
?- time(true).
yes
?- time(fail).
no
?- time(repeat(3)).
yes;
yes;
yes
test(V1,V2,V3,V4,V5,V6,V7,V8,V9) :-
write(V1), write(' '),
write(V2), write(' '),
write(V3), write(' '),
write(V4), write(' '),
write(V5), write(' '),
write(V6), write(' '),
write(V7), write(' '),
write(V8), write(' '),
write(V9).
?- call(test(1,2,3,4,5,6,7,8,9)).
1 2 3 4 5 6 7 8 9
yes
?- call(test(1,2,3,4,5,6,7,8), q).
1 2 3 4 5 6 7 8 q
yes
?- call(test(1,2,3,4,5,6,7), q, w).
1 2 3 4 5 6 7 q w
yes
?- call(test(1,2,3,4,5,6), q, w, e).
1 2 3 4 5 6 q w e
yes
?- call(test(1,2,3,4,5), q, w, e, r).
1 2 3 4 5 q w e r
yes
?- call(test(1,2,3,4), q, w, e, r, t).
1 2 3 4 q w e r t
yes
?- call(test(1,2,3), q, w, e, r, t, y).
1 2 3 q w e r t y
yes
?- call(test(1,2), q, w, e, r, t, y, u).
1 2 q w e r t y u
yes
?- call(test(1), q, w, e, r, t, y, u, i).
1 q w e r t y u i
yes
?- call(test, q, w, e, r, t, y, u, i, o).
q w e r t y u i o
yes