I'm baffled by the very basics of Prolog.
If I have this knowledge base:
loves(vincent, mia).
loves(marcellus, mia).
loves(pumpkin, honey_bunny).
loves(honey_bunny, pumpkin).
jealous(X, Y) :-
loves(X, Z),
loves(Y, Z).
Then I assume
"X is jealous of Y if X loves Z and Y loves Z"
When I run the query jealous(X, Y).
I get
X = Y, Y = vincent
X = vincent,
Y = marcellus
X = marcellus,
Y = vincent
X = Y, Y = marcellus
X = Y, Y = pumpkin
X = Y, Y = honey_bunny
I can see that vincent is jealous of marcellius and marcellius is jealous of vincent, but what do the lines in the form X = Y, Y = vincent
tell me please? I'm assuming that when there is a match, the next lines give the values where the query is true, as in
X = Y, Y = vincent
X = vincent,
Y = marcellus
X = marcellus,
Y = vincent
and that having nothing like that below X = Y, Y = marcellus
and the others means no match. But X = Y, Y = vincent
makes no sense to me. It would make sense if it meant "X is some value Y
, let's suppose Y
is vincent." But that would not explain X = marcellus, Y = vincent
in the result.
Any help understanding this much appreciated.