You doubt it, why isn’t it allowed?

Asked

Viewed 25 times

-1

Good morning. I was answering an exercise of Prolog that was passed to me by the teacher and really could not get an answer to that, the same question why the following rule: k(X),p(X),y(X) :- q(X), y(X). It is not allowed in a program in the language Prolog. Could someone give me a light on? I already gave a good search and could not visualize anything.

1 answer

0

The rules in Prolog have only one consequent (the "head" of the clause).

In its example, it reads "if q(X) and y(X) are valid, k(X), p(X) and y(X) are valid". Ignoring circular logic in y(X), you could write in Prolog as separate clauses:

k(X) :- q(X), y(X).
p(X) :- q(X), y(X).
y(X) :- q(X), y(X).

or, more compact,

k(X) :- q(X), y(X).
p(X) :- k(X).
y(X) :- k(X).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.