2

我有以下序言代码:

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

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

goal q.

如何获得两个解决方案?

4

1 回答 1

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.
于 2012-05-26T15:59:32.987 回答