From what i know, conjunction has greater precedence than disjunction.
We have the following knowledge base:
a(1).
a(2,3).
a(3,2).
a(4,5,3).
b.
b(1,2).
b(3).
c.
Our goal is:
?- a(X,Y);b(Z),c,fail,d.
So here's the problem: My teacher says that the goal gets broken into 4 subgoals, connected by conjunction:
(a(X,Y);b(Z)),
c,
fail,
d.
and that i shouldn't get no results when executing this query. But conjunction has greater precedence, right? Isn't the goal supposed to be broken into two subgoals(not four), connected by disjunction:
a(X,Y);
b(Z),c,fail,d.
So now I'm wondering who's right and who's wrong. Can somebody explain?
**I'm actually getting results when i execute the query.
I think the problem is primarily a misunderstanding that's due to the overloaded use of the word "precedence".
Prolog operators are defined by the extensible predicate op(+Precedence, +Type, :Name)
where Precedence
is an integer between 0 and 1200, Type
specifies associativity, and Name
gives the actual operator.
This table shows some predefined operators:
1100 xfy ;, |
1000 xfy ,
For historical reasons, a smaller integer value of Precedence
means that an operator binds tighter (i.e., that it has higher precedence).
So the precedence of the disjunction operator is lower than the one of the conjunction operator, because its value of Precedence
is higher.