# Problem with Backtracking of Solutions

38 views

### 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.
woman(carla).
woman(maria).
woman(anna).
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?

Thanks.

### 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!

Actions:

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

Action?
~~~~

--
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 swi-prolog+...@googlegroups.com.