Home Contents Index Summary Previous Next

2.11 Environment Control (Prolog flags)

The predicates current_prolog_flag/2 and set_prolog_flag/2 allow the user to examine and modify the execution environment. It provides access to whether optional features are available on this version, operating system, foreign-code environment, command-line arguments, version, as well as runtime flags to control the runtime behaviour of certain predicates to achieve compatibility with other Prolog environments.

current_prolog_flag(?Key, -Value)
The predicate current_prolog_flag/2 defines an interface to installation features: options compiled in, version, home, etc. With both arguments unbound, it will generate all defined prolog-flags. With the `Key' instantiated it unify the value of the prolog-flag. Features come in three types: boolean prolog-flags, prolog-flags with an atom value and prolog-flags with an integer value. A boolean prolog-flag is true iff the prolog-flag is present and the Value is the atom true. Currently defined keys in alphabetical order:

abort_with_exception(bool, changeable)
Determines how abort/0 is realised. See the description of abort/0 for details.

agc_margin(integer, changeable)
If this amount of atoms has been created since the last atom-garbage collection, perform atom garbage collection at the first opportunity. Initial value is 10,000. May be changed. A value of 0 (zero) disables atom garbage collection. See also PL_register_atom().

allow_variable_name_as_functor(bool, changeable)
If true (default is false), Functor(arg) is read as if it was written 'Functor'(arg). Some applications use the Prolog read/1 predicate for reading an application defined script language. In these cases, it is often difficult to explain to non-Prolog users of the application that constants and functions can only start with a lowercase letter. Variables can be turned into atoms starting with an uppercase atom by calling read_term/2 using the option variable_names and binding the variables to their name. Using this feature, F(x) can be turned into valid syntax for such script languages. Suggested by Robert van Engelen. SWI-Prolog specific.

argv(list)
List is a list of atoms representing the command-line arguments used to invoke SWI-Prolog. Please note that all arguments are included in the list returned.

arch(atom)
Identifier for the hardware and operating system SWI-Prolog is running on. Used to select foreign files for the right architecture. See also section 9.4 and file_search_path/2.

associate(atom, changeable)
On Windows systems, this is set to the filename-extension (e.g. pl or pro associated with plwin.exe.

autoload(bool, changeable)
If true (default) autoloading of library functions is enabled. See section 2.13.

backquoted_string(bool, changeable)
If true (default false), read translates text between backquotes into a string object (see section 4.23). This flag is mainly for compatibility to LPA Prolog.

bounded(true)
ISO prolog-flag describing integer representation is bound by min_integer and min_integer.

c_cc(atom)
Name of the C-compiler used to compile SWI-Prolog. Normally either gcc or cc. See section 9.7.

c_ldflags(atom)
Special linker flags passed to link SWI-Prolog. See section 9.7.

c_libs(atom)
Libraries passed to the C-linker when SWI-Prolog was linked. May be used to determine the libraries needed to create statically linked extensions for SWI-Prolog. See section 9.7.

char_conversion(bool, changeable)
Determines whether character-conversion takes place while reading terms. See also char_conversion/2.

character_escapes(bool, changeable)
If true (default), read/1 interprets \ escape sequences in quoted atoms and strings. May be changed. This flag is local to the module in which it is changed.

compiled_at(atom)
Describes when the system has been compiled. Only available if the C-compiler used to compile SWI-Prolog provides the __DATE__ and __TIME__ macros.

console_menu(bool)
Set to true in plwin.exe to indicate the console supports menus. See also section 4.35.2.

dde(bool)
Set to true if this instance of Prolog supports DDE as described in section 4.43.

debug(bool, changeable)
Switch debugging mode on/off. If debug mode is activated the system traps encountered spy-points (see spy/1) and trace-points (see trace/1). In addition, tail-recursion optimisation is disabled and the system is more conservative in destroying choice-points to simplify debugging.

Disabling these optimisations can cause the system to run out of memory on programs that behave correctly if debug mode is off.

debug_on_error(bool, changeable)
If true, start the tracer after an error is detected. Otherwise just continue execution. The goal that raised the error will normally fail. See also fileerrors/2 and the prolog-flag report_error. May be changed. Default is true, except for the runtime version.

debugger_print_options(term, changeable)
This argument is given as option-list to write_term/2 for printing goals by the debugger. Modified by the `w', `p' and `<N> d' commands of the debugger. Default is [quoted(true), portray(true), max_depth(10), attributes(portray)].

debugger_show_context(bool, changeable)
If true, show the context module while printing a stack-frame in the tracer. Normally controlled using the `C' option of the tracer.

double_quotes(codes,chars,atom,string, changeable)
This flag determines how double-quotes strings are read by Prolog and is ---like character_escapes--- maintained for each module. If codes (default), a list of character-codes is returned, if chars a list of one-character atoms, if atom double quotes are the same as single-quotes and finally, string reads the text into a Prolog string (see section 4.23). See also atom_chars/2 and atom_codes/2.

dynamic_stacks(bool)
If true, the system uses some form of `sparse-memory management' to realise the stacks. If false, malloc()/realloc() are used for the stacks. In earlier days this had consequenses for foreign code. As of version 2.5, this is no longer the case.

Systems using `sparse-memory management' are a bit faster as there is no stack-shifter, and checking the stack-boundary is often realised by the hardware using a `guard-page'. Also, memory is actually returned to the system after a garbage collection or call to trim_stacks/0 (called by prolog/0 after finishing a user-query).

editor(atom, changeable)
Determines the editor used by edit/1. See section 4.4 for details on selecting the editor used.

emacs_inferior_process(bool)
If true, SWI-Prolog is running as an inferior process of (GNU/X-)Emacs. SWI-Prolog assumes this is the case if the environment variable EMACS is t and INFERIOR is yes.

executable(atom)
Path-name of the running executable. Used by qsave_program/2 as default emulator.

file_name_variables(bool, changeable)
If true (default false), expand $varname and in arguments of builtin-predicates that accept a file name (open/3, exists_file/1, access_file/2, etc.). The predicate expand_file_name/2 should be used to expand environment variables and wildcard patterns. This prolog-flag is intended for backward compatibility with older versions of SWI-Prolog.

float_format(atom, changeable)
C-library printf() format specification used by write/1 and friends to determine how floating point numbers are printed. The default is %g. The specified value is passed to printf() without further checking. For example, if you want more digits printed, %.12g will print all floats using 12 digits instead of the default 6.

When using quoted-write, the output is guaranteed to contain a decimal dot or exponent, so read/1 reads a floating point number. See also format/[1,2], write_term/[2,3].

gc(bool, changeable)
If true (default), the garbage collector is active. If false, neither garbage-collection, nor stack-shifts will take place, even not on explicit request. May be changed.

generate_debug_info(bool, changeable)
If true (default) generate code that can be debugged using trace/0, spy/1, etc. Can be set to false using the -nodebug. The predicate load_files/2 restores the value of this flag after loading a file, causing modifications to be local to a source-file. Many of the libraries have :- set_prolog_flag(generate_debug_info, false) to hide their details from a normal trace. (7)

gui(bool)
Set to true if XPCE is around and can be used for graphics.

history(integer, changeable)
If integer> 0, support Unix csh(1) like history as described in section 2.7. Otherwise, only support reusing commands through the commandline editor. The default is to set this prolog-flag to 0 if a commandline editor is provided (see prolog-flag readline) and 15 otherwise.

home(atom)
SWI-Prolog's notion of the home-directory. SWI-Prolog uses it's home directory to find its startup file as <home>/boot32.prc (32-bit machines) or <home>/boot64.prc (64-bit machines) and to find its library as <home>/library.

hwnd(integer)
In plwin.exe, this refers to the MS-Windows window-handle of the console window.

integer_rounding_function(down,toward_zero)
ISO prolog-flag describing rounding by // and rem arithmetic functions. Value depends on the C-compiler used.

iso(bool, changeable)
Include some weird ISO compatibility that is incompatible to normal SWI-Prolog behaviour. Currently it has the following effect:
  • is/2 and evaluation under flag/3 do not automatically convert floats to integers if the float represents an integer.
  • The //2 (float division) always return a float, even if applied to integers that can be divided.
  • In the standard order of terms (see section 4.6.1), all floats are before all integers.
  • atom_length/2 yields an instantiation error if the first argument is a number.
  • clause/[2,3] raises a permission error when accessing static predicates.
  • abolish/[1,2] raises a permission error when accessing static predicates.

large_files(bool)
If true, SWI-Prolog has been compiled with large file support (LFS) and is capable to access files larger than 2GB on 32-bit hardware. Large file-support is default on installations built using configure that support it and may be switched off using the configure option --disable-largefile. (8)

max_arity(unbounded)
ISO prolog-flag describing there is no maximum arity to compound terms.

max_integer(integer)
Maximum integer value. Most arithmetic operations will automatically convert to floats if integer values above this are returned.

max_tagged_integer(integer)
Maximum integer value represented as a `tagged' value. Tagged integers require 4-bytes storage and are used for indexing. Larger integers are represented as `indirect data' and require 16-bytes on the stacks (though a copy requires only 4 additional bytes).

min_integer(integer)
Minimum integer value.

min_tagged_integer(integer)
Start of the tagged-integer value range.

open_shared_object(bool)
If true, open_shared_object/2 and friends are implemented, providing access to shared libraries (.so files) or dynamic link libraries (.DLL files).

optimise(bool, changeable)
If true, compile in optimised mode. The initial value is true if Prolog was started with the -O commandline option.

Currently optimise compilation implies compilation of arithmetic, and deletion of redundant true/0 that may result from expand_goal/2.

Later versions might imply various other optimisations such as integrating small predicates into their callers, eliminating constant expressions and other predictable constructs. Source code optimisation is never applied to predicates that are declared dynamic (see dynamic/1).

pid(int)
Process identifier of the running Prolog process. Existence of this flag is implementation dependent.

pipe(bool, changeable)
If true, open(pipe(command), mode, Stream), etc. are supported. Can be changed to disable the use of pipes in applications testing this feature. Not recommended.

readline(bool)
If true, SWI-Prolog is linked with the readline library. This is done by default if you have this library installed on your system. It is also true for the Win32 plwin.exe version of SWI-Prolog, which realises a subset of the readline functionality.

resource_database(atom)
Set to the absolute-filename of the attached state. Typically this is the file boot32.prc, the file specified with -x or the running executable. See also resource/3.

report_error(bool, changeable)
If true, print error messages, otherwise suppress them. May be changed. See also the debug_on_error prolog-flag. Default is true, except for the runtime version.

runtime(bool)
If true, SWI-Prolog is compiled with -DO_RUNTIME, disabling various useful development features (currently the tracer and profiler).

saved_program(bool)
If true, Prolog is started from a state saved with qsave_program/[1,2].

shared_object_extension(atom)
Extension used by the operating system for shared objects. .so for most Unix systems and .dll for Windows. Used for locating files using the file_type executable. See also absolute_file_name/3.

signals(bool)
Determine whether Prolog is handling signals (software interrupts). This flag is false if the hosting OS does not support signal handling or the command-line option -nosignals is active. See section 9.6.19.1 for details.

system_thread_id(int)
On MT systems (section 8, refers to the thread-identifier used by the system for the calling thread. See also thread_self/1.

tail_recursion_optimisation(bool, changeable)
Determines whether or not tail-recursion optimisation is enabled. Normally the value of this flag is equal to the debug flag. As programs may run out of stack if tail-recursion optimisation is omitted, it is sometimes necessary to enable it during debugging.

toplevel_print_anon(bool, changeable)
If true, toplevel variables starting with an underscore (_) are printed normally. If false they are hidden. This may be used to hide bindings in complex queries from the toplevel.

toplevel_print_options(term, changeable)
This argument is given as option-list to write_term/2 for printing results of queries. Default is [quoted(true), portray(true), max_depth(10), attributes(portray)].

toplevel_var_size(int, changeable)
Maximum size counted in literals of a term returned as a binding for a variable in a toplevel query that is saved for re-use using the $ variable reference. See section 2.8.

trace_gc(bool, changeable)
If true (false is the default), garbage collections and stack-shifts will be reported on the terminal. May be changed.

tty_control(bool)
Determines whether the terminal is switched to raw mode for get_single_char/1, which also reads the user-actions for the trace. May be set. See also the +/-tty command-line option.

unix(bool)
If true, the operating system is some version of Unix. Defined if the C-compiler used to compile this version of SWI-Prolog either defines __unix__ or unix. On other systems this flag is not available.

unknown(fail,warning,error, changeable)
Determines the behaviour if an undefined procedure is encountered. If fail, the predicates fails silently. If warn, a warning is printed, and execution continues as if the predicate was not defined and if error (default), an existence_error exception is raised. This flag is local to each module.

verbose(Atom, changeable)
This flags is used by print_message/2. If its value is silent, messages of type informational and banner are supressed. The -q switches the value from the initial normal to silent.

verbose_autoload(bool, changeable)
If true the normal consult message will be printed if a library is autoloaded. By default this message is suppressed. Intended to be used for debugging purposes.

verbose_file_search(bool, changeable)
If true (default false), print messages indicating the progress of absolute_file_name/[2,3] in locating files. Intended for debugging complicated file-search paths. See also file_search_path/2.

version(integer)
The version identifier is an integer with value:
10000 × Major + 100 × Minor + Patch
Note that in releases up to 2.7.10 this prolog-flag yielded an atom holding the three numbers separated by dots. The current representation is much easier for implementing version-conditional statements.

windows(bool)
If true, the operating system is an implementation of Microsoft Windows (3.1, 95/98/ME, NT/2000/XP, etc.). This flag is only available on MS-Windows based versions.

write_attributes(atom, changeable)
Defines how write/1 an friends write attributed variables. The option values are described with the attributes option of write_term/3. Default is ignore.

write_help_with_overstrike(bool)
Internal flag used by help/1 when writing to a terminal. If true it prints bold and underlined text using overstrike.

xpce(bool)
Set to true if the XPCE graphics system is loaded.

xpce_version(atom)
Set to the version of the loaded XPCE system.

set_prolog_flag(+Key, +Value)
Define a new prolog-flag or change its value. Key is an atom. If the flag is a system-defined flag that is not marked changeable above, an attempt to modify the flag yields a permission_error. If the provided Value does not match the type of the flag, a type_error is raised.

In addition to ISO, SWI-Prolog allows for user-defined prolog flags. The type of the flag is determined from the initial value and cannot be changed afterwards.