## 4.36 User Top-level Manipulation

break
  Recursively start a new Prolog top level. This Prolog top level has its own stacks, but shares the heap with all break environments and the top level. Debugging is switched off on entering a break and restored on leaving one. The break environment is terminated by typing the system's end-of-file character (control-D). If the -t toplevel command line option is given, this goal is started instead of entering the default interactive top level (prolog/0).
abort
  Abort the Prolog execution and restart the top level. If the -t toplevel command line option is given, this goal is started instead of entering the default interactive top level.

  Aborting is implemented by throwing the reserved exception `'$aborted'`. This exception can be caught using catch/3, but the recovery goal is wrapped with a predicate that prunes the choice points of the recovery goal (i.e., as once/1) and re-throws the exception. This is illustrated in the example below, where we press control-C and `a'.

      ?- catch((repeat,fail), E, true).
      ^CAction (h for help) ? abort
      % Execution Aborted

[ISO]halt
  Terminate Prolog execution. This is the same as `halt(0)`. See halt/1 for details.
[ISO]halt(+Status)
  Terminate Prolog execution with Status. This predicate calls PL_halt() which preforms the following steps:

  1. Set the Prolog flag exit_status to Status.

  2. Call all hooks registered using at_halt/1. If Status equals 0 (zero), any of these hooks calls cancel_halt/1, termination is cancelled.

  3. Call all hooks registered using PL_at_halt(). In the future, if any of these hooks returns non-zero, termination will be cancelled. Currently, this only prints a warning.

  4. Perform the following system cleanup actions:

     - Cancel all threads, calling thread_at_exit/1 registered termination hooks. Threads not responding within 1 second are cancelled forcefully.
     - Flush I/O and close all streams except for standard I/O.
     - Reset the terminal if its properties were changed.
     - Remove temporary files and incomplete compilation output.
     - Reclaim memory.

  5. Call exit(Status) to terminate the process
prolog
  This goal starts the default interactive top level. Queries are read from the stream `user_input`. See also the Prolog flag history. The prolog/0 predicate is terminated (succeeds) by typing the end-of-file character (typically control-D).

The following two hooks allow for expanding queries and handling the result of a query. These hooks are used by the top level variable expansion mechanism described in section 2.8.

expand_query(+Query, -Expanded, +Bindings, -ExpandedBindings)
  Hook in module `user`, normally not defined. Query and Bindings represents the query read from the user and the names of the free variables as obtained using read_term/3. If this predicate succeeds, it should bind Expanded and ExpandedBindings to the query and bindings to be executed by the top level. This predicate is used by the top level (prolog/0). See also expand_answer/2 and term_expansion/2.
expand_answer(+Bindings, -ExpandedBindings)
  Hook in module `user`, normally not defined. Expand the result of a successfully executed top-level query. Bindings is the query <Name>=<Value> binding list from the query. ExpandedBindings must be unified with the bindings the top level should print.