2
votes

Extending this question, what key presses are necessary to produce multiple solutions for SWI-Prolog?

Test code:

test(10).
test(1).

Attempted interaction:

?-test(X). // <- entered query

*pressing enter produces the following:

?-test(X).
X = 10.
 
?- // <- typing prompt here, pressing ";" here enters semi-colon character in new line.

According to the manual:

The user can type the semi-colon (;) or spacebar, if (s)he wants another solution. Use the return key if you do not want to see the more answers. Prolog completes the output with a full stop (.) if the user uses the return key or Prolog knows there are no more answers. If Prolog cannot find (more) answers, it writes false.

When should these keys (semicolon/space) be pressed, so that the programs gives multiple solutions instead of starting a new query?

1
I think your facts don't match what's loaded, because if you actually had both facts in your store, Prolog would have stopped at X = 10 and waited for you to either type the period or the semicolon. Because it didn't, it didn't think there were further solutions. Try member(X, [1,2,3]). to see what I'm talking about.Daniel Lyons
Did you reload the file, does the file contains some other content? Are there any compiler warnings/errors?Willem Van Onsem
I don't understand what you are trying to suggest here, there should always be a way to at least attempt to get multiple solutions, even if there is only one solutions. Doing that will just result in the solution being "false."user289661
@user289661 in practice, SWI Prolog and many others will not offer you more solutions if there is no choice point left on the stack, so you cannot ask for more solutions in cases like that.Daniel Lyons

1 Answers

0
votes

When you see

X = 10. 

?- 

(with the period already appearing) it means the dot was printed by Prolog itself, to signal there are no more solutions; the interaction with the query has already ended at this point, and it awaits your next query as indicated by the prompt ?-.

If Prolog "thought" there could be more solutions, then you'd see X = 10 _ (with a space after 0) and it would await your keypress, with cursor _ still on that line, without showing the prompt. And if you'd pressed the period at that point, aborting the search for more solutions yourself, the transcript would show

X = 10 .     % notice the space

?-