我有以下prolog代码:
predicates
like(string)
clauses
like(apple).
like(girl).
q :- like(A),write(A).
goal q.
如何获得两种解决方案?
答案 0 :(得分:1)
使用findall谓词 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).
或使用失败
domains
Z = symbol*
predicates
like(symbol)
clauses
like(apple).
like(girl).
goal like(X),write(X),nl,fail.