2

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?

Mike
  • 47,263
  • 29
  • 113
  • 177
BILL
  • 4,711
  • 10
  • 57
  • 96
  • 1
    I tried your query with swi-Prolog (with some little changes to the code, since the Edinburgh Prolog sintax is slighty different) and it gave me the (correct) answer you expected. In swi, when a query has multiple solutions you have to type a semicolon after each solution to get the next one. Have you tried that? – Haile May 26 '12 at 13:50
  • Where should a colon? In predicates section? – BILL May 26 '12 at 14:22
  • In the prolog interpreter window, when it prints > Alexandrov - has 1 child you tipe a semicolon and hit RET: – Haile May 26 '12 at 14:28
  • When I enter, once again displayed "Alexandrov - has 1 child" – BILL May 26 '12 at 14:44

1 Answers1

1

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.
BILL
  • 4,711
  • 10
  • 57
  • 96