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.
boolcan have the values
false. Some Prolog flags are not defined in all versions, which is normally indicated in the documentation below as ``if present and true''. A boolean Prolog flag is true iff the Prolog flag is present and the Value is the atom
true. Tests for such flags should be written as below:
( current_prolog_flag(windows, true) -> <Do MS-Windows things> ; <Do normal things> )
Some Prolog flags are scoped to a source file. This implies that if they are set using a directive inside a file, the flag value encountered when loading of the file started is restored when loading of the file is completed. Currently, the following flags are scoped to the source file: generate_debug_info and optimise.
A new thread (see section 9) copies all flags from the thread that created the new thread (its parent).15This is implemented using the copy-on-write tecnhnique. As a consequence, modifying a flag inside a thread does not affect other threads.
user, default) or a `system' view. In system view all system code is fully accessible as if it was normal user code. In user view, certain operations are not permitted and some details are kept invisible. We leave the exact consequences undefined, but, for example, system code can be traced using system access and system predicates can be redefined.
true, the operating system is MacOSX. Defined if the C compiler used to compile this version of SWI-Prolog defines
__APPLE__. Note that the unix is also defined for MacOSX.
false), dots may be embedded into atoms that are not quoted and start with a letter. The embedded dot must be followed by an identifier continuation character (i.e., letter, digit or underscore). The dot is allowed in identifiers in many languages, which can make this a useful flag for defining DSLs. Note that this conflicts with cascading functional notation. For example,
Post.meta.authoris read as
.(Post, 'meta.author'if this flag is set to
Functor(arg)is read as if it were 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_namesand 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.
--or the first non-option argument. See also os_argv.17Prior to version 6.5.2, argv was defined as os_argv is now. The change was made for compatibility reasone and because the current definition is more practical.
true(default) autoloading of library functions is enabled.
codes. If --traditional is given, the default is
symbol_char, which allows using
`in operators composed of symbols.18Older versions had a boolean flag
backquoted_strings, which toggled between
symbol_char. See also section 5.2.
true, integer representation is bound by min_integer and max_integer. If
falseintegers can be arbitrarily large and the min_integer and max_integer are not present. See section 188.8.131.52.
-lswiplif the SWI-Prolog kernel is a shared (DLL). If the SWI-Prolog kernel is in a static library, this flag also contains the dependencies.
-lswiplon COFF-based systems. See section 10.5.
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.
library(ansi_term), which is loaded at startup if the two conditions below are both true. Note that this implies that setting this flag to
falsefrom the system or personal initialization file (see section 2.2 disables colored output. The predicate message_property/2 can be used to control the actual color scheme depending in the message type passed to print_message/2.
\+ current_prolog_flag(color_term, false)
' (see meta_predicate/1). Supported values are:
truein swipl-win.exe to indicate that the console supports menus. See also section 4.34.3.
library(thread). This flag is not available on systems where we do not know how to get the number of CPUs. This flag is not included in a saved state (see qsave_program/1).
trueif this instance of Prolog supports DDE as described in section 4.42.
Disabling these optimisations can cause the system to run out of memory on programs that behave correctly if debug mode is off.
true, start the tracer after an error is detected. Otherwise just continue execution. The goal that raised the error will normally fail. See also the Prolog flag report_error. Default is
[quoted(true), portray(true), max_depth(10), attributes(portray)].
true, show the context module while printing a stack-frame in the tracer. Normally controlled using the `C' option of the tracer.
swi. The code below is a reliable and portable way to detect SWI-Prolog.
is_dialect(swi) :- catch(current_prolog_flag(dialect, swi), _, fail).
string, which produces a string as described in section 5.2. If --traditional is given, the default is
codes, which produces a list of character codes, integers that represent a Unicode code-point. The value
charsproduces a list of one-character atoms and the value
atommakes double quotes the same as single quotes, creating a atom. See also section 5.
textmode. The initial value is deduced from the environment. See section 2.18.1 for details.
in arguments of built-in predicates that accept a file name (open/3, exists_file/1, access_file/2, etc.). The predicate expand_file_name/2 can be used to expand environment variables and wildcard patterns. This Prolog flag is intended for backward compatibility with older versions of SWI-Prolog.
true(default) generate code that can be debugged using trace/0, spy/1, etc. Can be set to
falseusing the -nodebug. This flag is scoped within a source file. Many of the libraries have
:- set_prolog_flag(generate_debug_info, false)to hide their details from a normal trace.19In the current implementation this only causes a flag to be set on the predicate that causes children to be hidden from the debugger. The name anticipates further changes to the compiler.
trueif XPCE is around and can be used for graphics.
<home>/boot32.prc(32-bit machines) or
<home>/boot64.prc(64-bit machines) and to find its library as
remarithmetic functions. Value depends on the C compiler used.
(float division) always returns a float, even if applied to integers that can be divided.
f(',',a). Unquoted commas can only be used to separate arguments in functional notation and list notation, and as a conjunction operator. Unquoted bars can only appear within lists to separate head and tail, like
[Head|Tail], and as infix operator for alternation in grammar rules, like
a --> b | c.
[a :- b, c].must now be disambiguated to mean
[(a :- b), c].or
[(a :- b, c)].
X == -, true.write
X == (-), true.Currently, this is not entirely enforced.
true, SWI-Prolog has been compiled with large file support (LFS) and is capable of accessing 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
false(default), unification succeeds, creating an infinite tree. Using
true, unification behaves as unify_with_occurs_check/2, failing silently. Using
error, an attempt to create a cyclic term results in an
occurs_checkexception. The latter is intended for debugging unintentional creations of cyclic terms. Note that this flag is a global flag modifying fundamental behaviour of Prolog. Changing the flag from its default may cause libraries to stop functioning properly.
.sofiles) or dynamic link libraries (
true, compile in optimised mode. The initial value is
trueif Prolog was started with the -O command line option. The optimise flag is scoped to a source file.
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).
open(pipe(command), mode, Stream), etc. are supported. Can be changed to disable the use of pipes in applications testing this feature. Not recommended.
determinism, which implies the system prompts for alternatives if the goal succeeded while leaving choice points. Many classical Prolog systems behave as
groundness: they prompt for alternatives if and only if the query contains variables.
qcompile(+Atom)option of load_files/2.
boot32.prc, the file specified with -x or the running executable. See also resource/3.
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.
true, SWI-Prolog is compiled with -DO_RUNTIME, disabling various useful development features (currently the tracer and profiler).
false), load_files/2 calls hooks to allow library(sandbox) to verify the safety of directives.
true, Prolog has been started from a state saved with qsave_program/[1,2].
.sofor most Unix systems and
.dllfor Windows. Used for locating files using the
executable. See also absolute_file_name/3.
falseif the hosting OS does not support signal handling or the command line option -nosignals is active. See section 10.4.21.1 for details.
true(full checking) and
loose. Using checking mode
loose(default), the system accepts byte I/O from text stream that use ISO Latin-1 encoding and accepts writing text to binary streams.
resource_error(table_space)exception is raised.
timezonevariable associated with the POSIX tzset() function. See also format_time/3.
true, top-level variables starting with an underscore (
_) are printed normally. If
falsethey are hidden. This may be used to hide bindings in complex queries from the top level.
false) show the internal sharing of subterms in the answer substitution. The example below reveals internal sharing of leaf nodes in red-black trees as implemented by the
library(rbtrees)predicate rb_new/1 :
?- set_prolog_flag(toplevel_print_factorized, true). ?- rb_new(X). X = t(_S1, _S1), % where _S1 = black('', _G387, _G388, '').
If this flag is
% where notation
is still used to indicate cycles as illustrated below. This example also
shows that the implementation reveals the internal cycle length, and not
the minimal cycle length. Cycles of different length are
indistinguishable in Prolog (as illustrated by
S == R).
?- S = s(S), R = s(s(R)), S == R. S = s(S), R = s(s(R)).
[quoted(true), portray(true), max_depth(10), attributes(portray)].
~(tilde) sequences are replaced:
|Type in module if
|Break level if not 0 (see break/0)|
|Debugging state if not normal execution (see debug/0, trace/0)|
|History event if history is enabled (see flag history)|
variable reference. See section 2.8.
false), garbage collections and stack-shifts will be reported on the terminal. May be changed. Values are reported in bytes as G+T, where G is the global stack value and T the trail stack value. `Gained' describes the number of bytes reclaimed. `used' the number of bytes on the stack after GC and `free' the number of bytes allocated, but not in use. Below is an example output.
% GC: gained 236,416+163,424 in 0.00 sec; used 13,448+5,808; free 72,568+47,440
true, `traditional' mode has been selected using --traditional. See also section 5.
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. On other systems this flag is not available. See also apple and windows.
fail, the predicate fails silently. If
warn, a warning is printed, and execution continues as if the predicate was not defined, and if
existence_errorexception is raised. This flag is local to each module and inherited from the module's import-module. Using default setup, this implies that normal modules inherit the flag from
user, which in turn inherit the value
system. The user may change the flag for module
userto change the default for all application modules or for a specific module. It is strongly advised to keep the
errordefault and use dynamic/1 and/or multifile/1 to specify possible non-existence of a predicate.
false), unload all loaded foreign libraries. Default is
falsebecause modern OSes reclaim the resources anyway and unloading the foreign code may cause registered hooks to point to no longer existing data or code.
error. The first two create the flag on-the-fly, where
warningprints a message. The value
erroris consistent with ISO: it raises an existence error and does not create the flag. See also create_prolog_flag/3. The default is
silent, but future versions may change that. Developers are encouraged to use another value and ensure proper use of create_prolog_flag/3 to create flags for their library.
silent, messages of type
bannerare suppressed. The -q switches the value from the initial
truethe normal consult message will be printed if a library is autoloaded. By default this message is suppressed. Intended to be used for debugging purposes.
full(print a message at the start and end of each file loaded),
normal(print a message at the end of each file loaded),
brief(print a message at end of loading the toplevel file), and
silent(no messages are printed, default). The value of this flag is normally controlled by the option
silent(Bool)provided by load_files/2.
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.
10000 × Major + 100 × Minor + PatchNote 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.
true(default), a warning is printed if an implicitly imported predicate is clobbered by a local definition. See use_module/1 for details.
true, the operating system is an implementation of Microsoft Windows (NT/2000/XP, etc.). This flag is only available on MS-Windows based versions.
attributesoption of write_term/3. Default is
trueit prints bold and underlined text using overstrike.
trueif the XPCE graphics system is loaded.
permission_error. If the provided Value does not match the type of the flag, a
Some flags (e.g., unknown) are maintained on a per-module basis. The addressed module is determined by the Key argument.
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. Defined types are
boolean (if the
initial value is one of
atom if the initial value is any other atom,
if the value is an integer that can be expressed as a 64-bit signed
value. Any other initial value results in an untyped flag that can
represent any valid Prolog term.
read_only. The default is
term. The default is determined from the initial value. Note that
termrestricts the term to be ground.
true, do not modify the flag if it already exists. Otherwise (default), this predicate behaves as set_prolog_flag/2 if the flag already exists.