Problem with Backtracking of Solutions

Skip to first unread message

Andrea Chiera

Jan 20, 2019, 6:32:34 AM1/20/19
to SWI-Prolog
Hi, i have a problem with this prolog:
sister(X,Y):- woman(X), father(Z,X), father(Z,Y), X\=Y.
sister(X,Y):- woman(X), mother(Z,X), mother(Z,Y), X\=Y.
mother(carla, giovanni).
mother(carla, anna).
mother(carla, maria).
father(luigi, maria).
father(pasquale, maria).

If i use prolog's interpreter and i submit this query: "sister(maria, X)", Prolog gives me one solution (X=giovanni) if i type two time enter, and it gives me all solution if i types enter one time following by differents space for the each other solution. But at the end for the second case, it gives me "false". Why doesn't Prolog give me all solution when i run query the first time?


Boris Vassilev

Jan 20, 2019, 8:02:38 AM1/20/19
to SWI-Prolog
What you are seeing is expected behavior.

First enter starts the query.

Second enter means "exit".

Space means "redo" or "try to find other solution".

"false" after second redo means "did not find any more solutions".

If you type "h" (stands for "help") after the first solution you will see what actions are available, like this:

?- sister(maria, X).
X = giovanni % typed "h" here!


; (n, r, space, TAB): redo    t:          trace & redo
b:                    break   c (a, RET): exit
w:                    write   p           print
h (?):                help


You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
Visit this group at
For more options, visit

Andrea Chiera

Jan 21, 2019, 2:49:56 AM1/21/19
to SWI-Prolog
hi, thanks so mush, i thought that this beahiour was wrong. Thanks.
Reply all
Reply to author
0 new messages