Consider the Prolog predicated p(integer),q(integer),r(integer) with the flow model (o) and the predicate s:
p(1). q(1). r(1).
p(2). q(2). r(2).
s:-!,p(X),q(Y),r(Z),write(X,Y,Z),nl.
Give the result of the following goal: s. Justify the answer.
The result is 111,112,121,122,211,212,221,222. I have seen that the cut has no effect if it is at the beginning of a clause. Is this true?
Not exactly. That will depend on whether such predicate has other clauses or not.
Moreover:
writeis unary and it cannot be called with three arguments.The correct program would be:
Indeed, for this program, the
cuthas no effect. However, consider the following new version of the program.In this case, the
cutin the first clause of predicateswill prevent the execution of the second one.