0

I have a prolog program which includes some predicates, when i query one of the predicates it displays the true output, but it doesn't put the "." at the end and go to the next query. ChatGPT cannot even understand the problem and i cannot think of anything to do What might be the problem? (i am not able to share my code) The predicate calls a recursive predicate inside it and the results are correct i get

1 ?- predicate(1,2,A,B).
A=1,
B=2  

instead of

1 ?- predicate(1,2,A,B).
A=1,
B=2.

2 ?-
false
  • 10,264
  • 13
  • 101
  • 209
  • Do you have an infinite loop (possibly caused by calling the same predicate with the same arguments)? – coredump Apr 21 '23 at 12:29

1 Answers1

1

The toplevel doesn't print the dot . because there were some choicepoints left, that upon backtracking will try to find another solution.

Press <space>, ; or <enter>(*) to let the prolog engine try to find another solution, or press <esc>, a or . to cancel further searching for other solutions.

If you want to stop automatically after searching the first solution wrap your query on a once goal, like this:

?- once(predicate(1,2,A,B)).
A = 1,
B = 2.

(*) According to SWI documentation <enter> would stop further searching for alternative solutions but that's not what I geton my SWI 8.5.20 toplevel.

gusbro
  • 22,357
  • 35
  • 46
  • Needs correcting for and - see https://www.swi-prolog.org/pldoc/man?section=execquery – brebs Apr 21 '23 at 07:39
  • It's strange that in my SWI `enter` can be used to search for another solution instead of canceling further search as noted in that document. – gusbro Apr 21 '23 at 12:55