Home Contents Index Summary Previous Next

2.11 Environment Control (Prolog flags)

The current system defines 2 different mechanisms to query and/or set properties of the environment: flag/3 and current_prolog_flag/2 as well as a number of special purpose predicates of which unknown/2, fileerrors/2 are examples. The ISO standard defines prolog_flag. It is likely that all these global features will be merged into a single in the future.

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:
Identifier for the hardware and operating system SWI-Prolog is running on. Used to determine the startup file as well as to select foreign files for the right architecture. See also section 5.4.
The version identifier is an integer with value:
10000 × Major + 100 × Minor + Patch
Note that in releases upto 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.
SWI-Prolog's notion of the home-directory. SWI-Prolog uses it's home directory to find its startup file as <home>/startup/startup.<arch> and to find its library as <home>/library.
Path-name of the running executable. Used by qsave_program/2 as default emulator.
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.
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.
If true, open_shared_object/2 and friends are implemented, providing access to shared libraries (.so files) or dynamic link libraries (.DLL files).
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.
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).

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 5.7.
Name of the C-compiler used to compile SWI-Prolog. Normally either gcc or cc. See section 5.7.
Special linker flags passed to link SWI-Prolog. See section 5.7.
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.
If true, Prolog is started from a state saved with qsave_program/[1,2].
If true, SWI-Prolog is compiled with -DO_RUNTIME, disabling various useful development features (currently the tracer and profiler).
Maximum integer value. Most arithmetic operations will automatically convert to floats if integer values above this are returned.
Minimum integer value.
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).
Start of the tagged-integer value range.
float_format(atom, changeable)
C 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. See also format/[1,2], write/1, print/1 and portray/1.
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)].
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)].
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.
Describes when the system has been compiled. Only available if the C-compiler used to compile SWI-Prolog provides the __DATE__ and __TIME__ macros.
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.
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 3.23). See also atom_chars/2 and atom_codes/2.
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 none-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.
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.
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.
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().
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 3.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.
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).

char_conversion(bool, changeable)
Determines whether character-conversion takes place while reading terms. See also char_conversion/2.
autoload(bool, changeable)
If true (default) autoloading of library functions is enabled. See section 2.13.
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.
trace_gc(bool, changeable)
If true (false is the default), garbage collections and stack-shifts will be reported on the terminal. May be changed.
ISO prolog-flag describing there is no maximum arity to compound terms.
integer_rounding_function(down,toward_zero, changeable)
SO prolog-flag describing rounding by // and rem arithmetic functions. Value depends on the C-compiler used.
ISO prolog-flag describing integer representation is bound by min_integer and min_integer.
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.
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.
debug(bool, changeable)
Switch on/off debugging mode. 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.
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.
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.
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.
If true, the operating system is an implementation of Microsoft Windows (3.1, 95, NT, etc.).
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.