Home Contents Index Summary Previous Next

3.40 User Toplevel 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 start a new top level. If the -t toplevel command line options is given this goal is started instead of entering the default interactive top level. Break environments are aborted as well. All open files except for the terminal related files are closed. The input- and output stream again refers to user. (21)

In the single-threaded version abort/0 is implemented using a C-longjmp() call, after which the Prolog stacks are emptied, relevant reference-counts and some other global data is reset, after which the system is restarted. This approach allows Prolog to recover from internal consistency problems such as garbage-collection errors. The multi-threaded version implements abort/0 by generation an exception $aborted. This approach is less secure if the system is in an unhealthy state, but required to ensure consistency of the other threads as well as mutexes.

halt
Terminate Prolog execution. Open files are closed and if the command line option -tty is not active the terminal status (see Unix stty(1)) is restored. Hooks may be registered both in Prolog and in foreign code. Prolog hooks are registered using at_halt/1. halt/0 is equivalent to halt(0).
halt(+Status)
Terminate Prolog execution with given status. Status is an integer. See also halt/0.
prolog
This goal starts the default interactive top level. Queries are read from the stream user_input. See also the history prolog_flag (current_prolog_flag/2). The prolog/0 predicate is terminated (succeeds) by typing the end-of-file character (On most systems control-D).

The following two hooks allow for expanding queries and handling the result of a query. These hooks are used by the toplevel 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 toplevel. This predicate is used by the toplevel (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 toplevel query. Bindings is the query <Name>=<Value> binding list from the query. ExpandedBindings must be unified with the bindings the toplevel should print.