简体   繁体   中英

How to correct predicate on Prolog?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM