Home Contents Index Summary Previous Next

2.8 Environment Control

The current system defines 3 different mechanisms to query and/or set properties of the environment: please/3, flag/3 and feature/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.

please(+Key, -Old, +New)
The predicate please/3 (5) is a solution to avoid large numbers of environment control predicates. Later versions will support other environment control as now provided via the predicates style_check/1, leash/1, unknown/2, the tracer predicates, etc. These predicates are then moved into a library for backwards compatibility. The currently available options are:

optimise (on/off) Default: off
Switch optimise mode for the compiler on or off (see also the command line option -O). Currently optimise compilation only implies compilation of arithmetic, making it fast, but invisible to the tracer. Later versions might imply various other optimisations such as incorporating a number of basic predicates in the virtual machine (var/1, fail/0, =/2, etc.) to gain speed at the cost of crippling the debugger. Also source level 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).

autoload (on/off) Default: on
If on autoloading of library functions is enabled. If off autoloading is disabled. See section 2.10.

verbose_autoload (on/off) Default: off
If on 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 (e.g. where does this predicate come from?).

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

arch (atom)
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 load_foreign/5.

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

home (atom)
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.

pipe (bool)
If true, tell(pipe(command)), etc. are supported.

load_foreign (bool)
If true, load_foreign/[2,5] are implemented.

open_shared_object (bool)
If true, open_shared_object/2 and friends are implemented, providing access to shared libraries (.so files). This requires the C-library functions dlopen() and friends as well as the configuration option --with-dlopen.

dynamic_stacks (bool)
If true, the system provides virtual memory based stack expansion. This makes stack-expansion safe when called from C and while running C-defined functions without these functions taking any precautions. Pure Prolog programs are not affected by this feature as the system will use stack-shifting to expand the stacks at runtime.

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.

c_staticlibs (atom)
On some machines, the SWI-Prolog executable is dynamically linked, but requires some libraries to be statically linked.

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

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

save (bool)
If true, save/[1,2] is implemented.

save_program (bool)
If true, save_program/[1,2] is implemented.

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.

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

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

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

min_integer (integer)
Minimum integer value.

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_tagged_integer (integer)
Start of the tagged-integer value range.

float_format (atom)
C printf() format specification used by write/1 and friends to determine how floating point numbers are printed. The default is %g. May be changed. 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.

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.

character_escapes (bool)
If true (default), read/1 interprets \ escape sequences in quoted atoms and strings. May be changed.

gc (bool)
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.

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

max_arity (unbounded)
ISO feature describing there is no maximum arity to compound terms.

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

bounded (true)
ISO feature describing integer representation is bound by min_integer and min_integer.

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.

debug_on_error (bool)
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 feature report_error. May be changed. Default is true, except for the runtime version.

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

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.

windows (bool)
If true, the operating system is an implementation of Microsoft Windows (3.1, 95, NT, etc.).

set_feature(+Key, +Value)
Define a new feature or change its value. Both arguments must be atoms.