Search code examples
prologeofswi-prologprolog-toplevel

How to send EOF on Prolog swipl REPL on Windows to close the pseudo user file?


I'm using the swipl.exe Prolog REPL on Windows and trying to use the user pseudo file opened with [user]. but I can't figure out the key shortcut to leave the pseudo file:

c:\code>swipl.exe
Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3)

1 ?- [user].
|: hello :- format('Hello world~n').
|: ^Z

.

ERROR: user://1:9:3: Syntax error: illegal_character
|:
Action (h for help) ? ^C
c:\code>

Starting at the ^Z I typed the keys

  • CTRL+Z
  • ENTER (I expected here should have sent the EOF)
  • ENTER
  • .
  • ENTER (this shows an error, and puts me back into the pseudo file)
  • CTRL+C (this kills only one of the two swipl processes, leaving the console in a broken state with some keystrokes going to swipl and some going to cmd(!))

I know that on a blank line pressing CTRL+Z then ENTER normally works to send EOF, like if in more.com I type A ENTER B ENTER CTRL+Z ENTER everything works on my terminal.


If I run the swipl-win.exe GUI following the same key steps, immediately when I press CTRL+Z it closes the pseudo file and returns me to the top-level query:


?- [user].
|: hello :- format('Hello world~n').
|: 
% user://1 compiled 0.00 sec, 1 clauses
true.

?- hello.
Hello world
true.

?- 

What do I press to get [user]. to work in swipl.exe?


Solution

  • As you noticed, when you type [user], you're consulting a pseudo source file, which is made of terms. Therefore, simply type the term end_of_file. For example:

    ?- [user].
    |: a.
    |: b.
    |: end_of_file.
    
    % user://1 compiled 0.00 sec, 2 clauses
    true.