It is well known that the following two rules
fruit(X) :- yellow(X).
fruit(X) :- red(X).
can be written more concisely as following using the disjunction ;
.
fruit(X) :- ( yellow(X); red(X) ).
Now, let's look at the following which introduces a cut before the disjunctive group.
test(specific) :- !, ( goal1 ; goal2 ).
test(General) :- goal3.
The idea is that if test(specific)
matches, then test(General)
is not executed.
Question: Is the above equivalent to the following?
test(specific) :- goal1.
test(specific) :- !, goal2.
test(General) :- goal3.
I ask because in the first form, the cut is present before the group consisting of both goals ( goal1 ; goal2 )
, but in the second form it is only present before goal2
, which feels asymmetric and that usually prompts me to check my understanding.
The context of this question is trying to better understand the answer to this question: Implementing cut in tracing meta interpreter prolog