prologprolog-toplevel

how to exit from swipl to bash?


stav> swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?-

The only way I found is to run cntr+c multiple times + exit + enter.

is there a simple way to exit?


Solution

  • Ctrl+D or halt..

    Interactive programs that read user input typically exit when you indicate that no more input is coming. Ctrl+D instructs the shell to tell the program that the EOF (end of file) has been reached, causing the program to exit.

    This works with virtually all REPLs (Python, NodeJS, Ruby, ...) and many other programs. One random example: Run md5sum on the command line and type in some text. When you're done, press Ctrl+D and see the MD5 hash of the text you entered.

    There is another Prolog-specific way to exit, which is the halt predicate (https://www.swi-prolog.org/pldoc/man?predicate=halt/0). Takes longer to type, but allows you to exit programmatically.