the cut has no effect if it is at the beginning of a clause."
Not exactly. That will depend on whether such predicate has other clauses or not.
Moreover:
- the predicate
write
is unary and it cannot be called with three arguments.
- it is better to group the clauses in the definition of the each predicate.
The correct program would be:
p(1). p(2).
q(1). q(2).
r(1). r(2).
s :- !, p(X), q(Y), r(Z), writeln(X-Y-Z).
Indeed, for this program, the cut
has no effect.
However, consider the following new version of the program.
p(1). p(2).
q(1). q(2).
r(1). r(2).
s :- !, p(X), q(Y), r(Z), writeln(X-Y-Z).
s :- writeln(here). % <= this clause will not be executed!
In this case, the cut
in the first clause of predicate s
will prevent the execution of the second one.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…