Reputation:
% facts
mother(john, dana).
father(john, david).
mother(chelsea, dana).
father(chelsea, david).
mother(jared, dana).
father(jared, david).
% queries
parent(X,Y) :- father(X,Y);mother(X,Y).
When I type in "parent(john, X).", I get X = dana, but not X== david. However, on my previous question, the person who responded to me seems to get both parents. Is this a limitation of gprolog or am I still doing something wrong?
Upvotes: 1
Views: 2678
Reputation:
In the interactive top-level query answering loop you get a next solution by typing the semicolon ";".
Your example works fine in GNU Prolog:
GNU Prolog 1.4.0
By Daniel Diaz
Copyright (C) 1999-2011 Daniel Diaz
| ?- [user].
compiling user for byte code...
mother(john, dana).
father(john, david).
parent(X,Y) :- father(X,Y);mother(X,Y).
user compiled, 4 lines read - 725 bytes written, 33109 ms
(2 ms) yes
| ?- parent(john,X).
X = david ? ;
X = dana
yes
Bye
Upvotes: 2
Reputation: 22585
To get all the results you have to press the semicolon key ;
, once for each solution.
If you want to get all the results as a list, you can try
?- findall(X, parent(john, X), L).
L = [david,dana]
Upvotes: 4