### 7.22 Prolog state

- `set_prolog_flag/2`
- `current_prolog_flag/2`
- `set_bip_name/2`
- `current_bip_name/2`
- `write_pl_state_file/1`, `read_pl_state_file/1`

#### 7.22.1 `set_prolog_flag/2`

Templates

  `set_prolog_flag(+flag, +term)`

Description

`set_prolog_flag(Flag, Value)` sets the value of the Prolog flag `Flag` to `Value`.

Prolog flags: a Prolog flag is an atom which is associated with a value that is either implementation defined or defined by the user. Each flag has a permitted range of values; any other value is a `domain_error`. The following two tables present available flags, the possible values, a description and if they are ISO or an extension. The first table presents unchangeable flags while the second one the changeable flags. For flags whose default values is machine independent, this value is underlined.

Unchangeable flags:

Flag | Values | Description | ISO
`bounded` | `true` / `false` | are integers bounded ? | Y
`max_integer` | an integer | greatest integer | Y
`min_integer` | an integer | smallest integer | Y
`integer_rounding_function` | `toward_zero` `down` | `rnd(X)` = integer part of `X` `rnd(X)` = ⌊`X⌋` (section 7.6.1) | Y
`max_arity` | an integer | maximum arity for compound terms (255) | Y
`max_atom` | an integer | maximum number of atoms | N
`max_unget` | an integer | maximum number of successive ungets | N
`prolog_name` | an atom | name of the Prolog system | N
`prolog_version` | an atom | version number of the Prolog system | N
`prolog_date` | an atom | date of the Prolog system | N
`prolog_copyright` | an atom | copyright message of the Prolog system | N

Changeable flags:

Flag | Values | Description | ISO
`char_conversion` | `on` / `off` | is character conversion activated ? | Y
`debug` | `on` / `off` | is the debugger activated ? | Y
`singleton_warning` | `on` / `off` | warn about named singleton variables ? | N
`strict_iso` | `on` / `off` | strict ISO behavior ? | N
`double_quotes` | `atom` `chars` `codes` `atom_no_escape` `chars_no_escape` `codes_no_escape` | a double quoted constant is returned as: an atom a list of characters a list of character codes as `atom` but ignore escape sequences as `chars` but ignore escape sequences as `code` but ignore escape sequences | Y N
`back_quotes` | `atom` `chars` `codes` `atom_no_escape` `chars_no_escape` `codes_no_escape` | a back quoted constant is returned as: an atom a list of characters a list of character codes as `atom` but ignore escape sequences as `chars` but ignore escape sequences as `code` but ignore escape sequences | N
`unknown` | `error` `warning` `fail` | a predicate calls an unknown procedure: an `existence_error` is raised a message is displayed then fails quietly fails | Y
`syntax_error` | `error` `warning` `fail` | a predicate causes a syntax error: a `syntax_error` is raised a message is displayed then fails quietly fails | N
`os_error` | `error` `warning` `fail` | a predicate causes an O.S. error: a `system_error` is raised a message is displayed then fails quietly fails | N

The `strict_iso` flag is introduced to allow a compatibility with other Prolog systems. When turned off the following relaxations apply:

- a callable term can be given as a predicate indicator.
- built-in predicates are found by `current_predicate/1` (section 7.8.1).

Errors

`Flag` is a variable |  | `instantiation_error`
`Value` is a variable |  | `instantiation_error`
`Flag` is neither a variable nor an atom |  | `type_error(atom, Flag)`
`Flag` is an atom but not a valid flag |  | `domain_error(prolog_flag, Flag)`
`Value` is inappropriate for Flag |  | `domain_error(flag_value, Flag+Value)`
`Value` is appropriate for `Flag` but flag `Flag` is not modifiable |  | `permission_error(modify, flag, Flag)`

Portability

ISO predicate. All ISO flags are implemented.

#### 7.22.2 `current_prolog_flag/2`

Templates

  `current_prolog_flag(?flag, ?term)`

Description

`current_prolog_flag(Flag, Value)` succeeds if there exists a Prolog flag that unifies with `Flag` and whose value unifies with `Value`. This predicate is re-executable on backtracking.

Errors

`Flag` is neither a variable nor an atom |  | `type_error(atom, Flag)`
`Flag` is an atom but not a valid flag |  | `domain_error(prolog_flag, Flag)`

Portability

ISO predicate.

#### 7.22.3 `set_bip_name/2`

Templates

  `set_bip_name(+atom, +arity)`

Description

`set_bip_name(Functor, Arity)` initializes the context of the error (section 5.3.1) with `Functor` and `Arity` (if `Arity` < 0 only `Functor` is significant).

Errors

`Functor` is a variable |  | `instantiation_error`
`Arity` is a variable |  | `instantiation_error`
`Functor` is neither a variable nor an atom |  | `type_error(atom, Functor)`
`Arity` is neither a variable nor an integer |  | `type_error(integer, Arity)`

Portability

GNU Prolog predicate.

#### 7.22.4 `current_bip_name/2`

Templates

  `current_bip_name(?atom, ?arity)`

Description

`current_bip_name(Functor, Arity)` succeeds if `Functor` and `Arity` correspond to the context of the error (section 5.3.1) (if `Arity` < 0 only `Functor` is significant).

Errors

`Functor` is neither a variable nor an atom |  | `type_error(atom, Functor)`
`Arity` is neither a variable nor an integer |  | `type_error(integer, Arity)`

Portability

GNU Prolog predicate.

#### 7.22.5 `write_pl_state_file/1`, `read_pl_state_file/1`

Templates

  `write_pl_state_file(+source_sink)
  read_pl_state_file(+source_sink)`

Description

`write_pl_state_file(FileName)` writes onto `FileName` all information that influences the parsing of a term (section 7.14). This allows a sub-process written in Prolog to read this file and then process any Prolog term as done by the parent process. This file can also be passed as argument of the `--pl-state` option when invoking `gplc` (section 3.4.3). More precisely the following elements are saved:

- all operator definitions (section 7.14.10).
- the character conversion table (section 7.14.12).
- the value of `char_conversion`, `double_quotes`, `back_quotes` and `singleton_warning` Prolog flags (section 7.22.1).

`read_pl_state_file(FileName)` reads (restores) from `FileName` all information previously saved by `write_pl_state_file/1.`

Errors

`FileName` is a variable |  | `instantiation_error`
`FileName` is neither a variable nor an atom |  | `type_error(atom, FileName)`
an operating system error occurs and the value of the `os_error` Prolog flag is `error` (section 7.22.1) |  | `system_error(atom explaining the error)`

Portability

GNU Prolog predicate.

Copyright (C) 1999-2007 Daniel Diaz Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved. More about the copyright