The most stupid question about interactive SWI prolog

I’m using: SWI-Prolog version 8.2.4.

In the interactive REPL, how can I end a statement without evaluation? How can I get out of an additional return?

Often I am in the situation that I press “enter” on a empty line and then I don’t now how to get “nicely” out of it. It looks like this: ("_" represents the cursor)

?-
|     _

Now typing just <RETURN> keeps me indented, typing . (dot) + <RETURN> brings up “ERROR: Stream user_input:720:6 Syntax error: Unexpected end of clause”, Ctrl-C doesn’t seem to help either.

I just want to get back to

?- _

Any way to do this? Maybe I’m missing the obvious here…

1 Like

No, no, I have the rules in, say, hanoi.pl and consult it with [hanoi], but when playing with calling the predicates in the REPL I easily type a superfluous <RETURN> - and just would like to get out of the indented

-     _

without the ugly Unexpected end of clause error.

Not really important, I guess.

That works. The | prompt is a continuation prompt telling you the input is incomplete. So, you can just keep typing, e.g.

?- <return>
|  write(hello).
hello
true.
?- 

Another popular trick if you use , (comma) rather than . (dot) by accident is to add true., e.g.,

?- write(hello),
|  true.
hello
true.
?- 

On some installations pressing ^C (control C) and a (abort) also works. It depends on the input method (plain terminal, GNU readline, BSD libedit, embedding in Emacs, ECliPSe, etc.).

2 Likes

I’ve had exactly the same thought, fyi! It’s something on my list for “when I have the chance to do something about it”. My usual solution is the (only slightly cleaner) ^C into the interrupt menu, then “a” to abort back to the toplevel. Advantage is, even if you had superfluous characters at the beginning of the previous line, they won’t get interpreted as a goal.

I would, however, like to make it possible to get back to a clean toplevel prompt more easily, so I’ll take that as a vote in that direction for when I’ve got some spare cycles :grinning_face_with_smiling_eyes:

1 Like

Ok, so I think the easiest to get out of the continuation pormpt is typing true.:

?-
|.   true.

?- _

This makes me happy. :grinning_face_with_smiling_eyes: Thanks for engaging in this maybe pointless question.

1 Like

If you are like me you will tire of typing true. often.

Try

?- assert(t :- true).
true.

Then you can

?- 
|    t.
true.
2 Likes