How to correct predicate on Prolog?

636 views Asked by At

I have the following prolog code:

predicates
like(string)
clauses
 like(apple).
like(girl).

q :- like(A),write(A).

goal q.

How to get two solutions?

1

There are 1 answers

0
BILL On BEST ANSWER

using findall predicate http://cs.union.edu/~striegnk/learn-prolog-now/html/node96.html

domains
Z = symbol*

predicates
like(symbol)
q(symbol)

clauses
like(apple).
like(girl).
q(A) :- like(A).

goal findall(X,q(X),Z),write(Z).

or using fail

domains
Z = symbol*

predicates
like(symbol)

clauses
like(apple).
like(girl).

goal like(X),write(X),nl,fail.