14 Setting Prolog Flags

SWI-Prolog has a set of flags that let you examine and configure the Prolog execution runtime. You can set Prolog flags from Emacs directly with the following command:

Command: sweeprolog-set-prolog-flag

Set the value of a Prolog flag.

This command let’s you interactively configure the embedded Prolog execution environment by changing the values of Prolog flags. It prompts you for a Prolog flag, with completion candidates annotated with their current values. Then, it prompts again for a Prolog term and sets the flag’s value to that term.

For more information about Prolog flags in SWI-Prolog, see Environment Control in the SWI-Prolog manual.

As an example, the Prolog flag double_quotes controls the interpretation of double quotes in Prolog code. By default, double_quotes is set to string, so for instance "foo" is read as a SWI-Prolog string. You can easily validate this in the Sweep top-level:

?- A = "foo".
A = "foo".

You can change the interpretation of double quotes to denote lists of character codes, by setting the value the double_quotes flag to codes with M-x sweeprolog-set-prolog-flag RET double_quotes RET codes RET. Evaluating A = "foo" again exhibits the different interpretation:

?- A = "foo".
A = [102, 111, 111].

Note that some flags have a thread-local value, and sweeprolog-set-prolog-flag always operates only on the main thread. To set flags in an existing top-level thread, use the predicate set_prolog_flag/2 directly in that top-level.