8.1.2 Prolog Language

8.1.2.1 Single Language Mode

Release 3 had the notion of multiple language modes: iso and sicstus. Release 4 does not have this notion. The syntax and semantics of the Prolog language correspond to the previous iso language mode.

8.1.2.2 DCG Notation

The exact rules for translating DCG rules to plain Prolog clauses have not been laid down in a standard, but there is a broad consensus in the Prolog community about what they should mean. One of the guiding principles is that the translation should be steadfast, in particular that the translated code should always treat its last argument as an output argument and not use it “too early”. In some cases, a non-steadfast translation was produced in release 3. This has been corrected in release 4.

8.1.2.3 Asserting Terms with Attributed Variables

In release 3, terms containing attributed variables and blocked goals could be asserted, copied, and gathered as solutions to findall/3 and similar predicates. The copy would contain new attributed variables with the attributes copied. This operation could be very expensive, could yield unexpected results and was not always safe e.g. in the context of CLPFD constraints. In release 4, the semantics of this operation has changed: in the copy, an attributed variable is simply replaced by a plain, brand new variable. Of course, if the same attributed variable occurs more than once, the same plain variable will occur in the corresponding places in the copy. If the attributes are relevant, the program can obtain them by using the new built-in predicate copy_term/3 described below.

8.1.2.4 Arithmetic

The infix operator `#' (bitwise exclusive or) has been renamed to `\'.

8.1.2.5 Syntax

Atoms can now contain the NUL character, i.e. character code zero. It is classified as white space and must therefore be entered using escapes. As an example 'a\0\a' is a three character atom containing two as separated by a NUL.

Internally, atom names and other encoded strings, use the non-shortest form `0xC0 0x80' to encode NUL. This is similar to how NUL is handled by Tcl/Tk and Java.

8.1.2.6 Prolog Flags

The language and wcx Prolog flag have been dropped.

The following Prolog flag is new:

quoted_charset
Controls the character set to use when writing quoted atoms.
8.1.2.7 Stream Properties

The wcx property has been dropped.

The following properties are new:

encoding_signature/1
Specifies whether an encoding signature (such as Unicode “byte order mark”) was used to determine the character encoding.
encoding/1
Subsumes the wcx/1 option of release 3.
eol/1
Specifies how line endings in the file should be handled if the stream is opened in text mode.
8.1.2.8 Statistics Keywords

The following keywords are new:

total_runtime
Measures the total CPU time used while executing, including memory management such as garbage collection but excluding system calls.
defragmentation
Measures the number of and time spent performing memory defragmentation.
8.1.2.9 Built-In Predicates

The set of built-in predicates has changed slightly. The following predicates have been removed:

'C'/3
This was used in the Prolog translation of DCG rules. It could trivially be replaced by unifications and served no other reasonable purpose.
get0/[1,2]
put/[1,2]
These used to have an overloaded semantics meaning one thing on binary streams and another thing on text streams. They have been subsumed by their ISO counterparts.
get/[1,2]
tab/[1,2]
skip/[1,2]
Although these do not have ISO counterparts, they have been removed for being in the spirit of get0/[1,2] and put/[1,2]. We have provided skip_char/[1,2], skip_code/[1,2], and skip_byte/[1,2] as an ISO style replacement for skip/[1,2].
ttyget0/1
ttyget/1
ttynl/0
ttyput/1
ttyskip/1
ttytab/1
ttyflush/0
These used to exist as shorthands for the respective predicate with an additional user argument. In most cases, the “respective predicate” is one of the non-ISO style predicate mentioned above, so there was no point in keeping the shorthand.
fileerrors/0
nofileerrors/0
These used to exist as shorthands for set_prolog_flag/2 with specific arguments, and so can be trivially replaced.
call_residue/2
Dropped because it was not possible to ensure the correct behavior in all circumstances, it relied heavily on copying terms with attributed variables, and it was not needed by any library module. It has been replaced by a similar predicate, call_residue_vars/2, which should suffice in most cases where call_residue/2 was used; see below.
undo/1
Dropped because it was not possible to ensure the correct behavior in all circumstances. Users that know what they are doing can still call the unsupported predicate prolog:undo/1. The argument should have a module prefix.
help/0
version/0
version/1
These predicates, managing and displaying messages, can be easily emulated by feaures of the message system.
fcompile/1
load/1
These predicates used to compile Prolog source code into `.ql' files, and load such files. `.ql' files serve a purpose when boot-strapping the Prolog system, but offer no advantages over `.po' files, the Prolog object code format used by other built-in predicates.
load_foreign_files/2
This predicate provided a shorthand for building and loading a temporary foreign resource. Working with foreign resources is straightforward, and so the shorthand was dropped.
require/1
This predicate provided a shorthand for locating and loading library predicates. This was originally introduced for a compatibility reason that is now obsolete. It is straightforward to provide the necessary :- use_module/2 directives, and so the shorthand was dropped.

The following predicates have been added:

call/N
Generalizes call/1. For example, call(p(1,2), a, b) is equivalent to call(p(1,2, a, b)).
skip_char/[1,2]
skip_code/[1,2]
skip_byte/[1,2]
ISO style replacements for the non-ISO style skip/[1,2].
call_residue_vars/2
Called as follows:
          call_residue_vars(:Goal, -Vars)
     

Executes the procedure call Goal, unifying Vars with the list of residual variables that have blocked goals or attributes attached to them.

copy_term/3
Called as follows:
          copy_term(+Term, -Copy, -Body)
     

Makes a copy of Term in which all variables have been replaced by new variables that occur nowhere outside the newly created term. If Term contains attributed variables, Body is unified with a term such that executing Body will reinstate equivalent attributes on the variables in Copy. Otherwise, Body is unified with true.

Some predicates have been changed slightly; in most cases, this affects predicates that take a list of options.

[F1,F2,...]
This is now a short-hand for load_files([F1,F2,...]).
is_mutable/1
The predicate is_mutable/1 has been renamed to mutable/1, in analogy with integer/1, atom/1 etc.
module/1
The predicate module/1 has been renamed to set_module/1, to avoid possible confusion with the module/2 declaration.
format/[2,3]
For the predicate format/[2,3], the semantics of the `~@' spec has changed slightly: the goal Arg is called as if by \+ \+ Arg, i.e. any bindings made by the goal are lost.
close/2
Takes new options:
direction/1
Specifies which directions to close.

open/4
The wcx/1 option has been dropped. Takes new options:
encoding_signature/1
encoding/1
eol/1
Correspond to the respective stream properties.
if_exists/1
Specifies what should happen if the file already exists.

absolute_file_name/3
The ignore_underscores/1 option has been dropped. The file_type/1 option value ql has been dropped, whereas the option value executable is new. The access/1 option values execute, executable and search are new. The glob/1 option is new, allowing to match file names against a pattern.
load_files/2
The load_type/1 option value ql has been dropped. encoding_signature/1, encoding/1, subsuming the wcx/1 option of release 3, and eol/1, are new options, corresponding to the respective stream properties.
write_term/3
The quoted_charset/1 option is new, reflecting the value of the Prolog flag with the same name.
halt/1
The predicate halt/1 now raises an internal exception like halt/0. This gives surrounding Prolog and C code an opportunity to perform cleanup.
profile_data/4
The Selection argument now takes one of the values: [calls,choice_points,instructions]. The Resolution argument now takes one of the values: [predicate,clause].
8.1.2.10 Hook Predicates

The hook user:term_expansion/[2,4] is replaced by the hook:

     user:term_expansion(Term1, Layout1, Tokens,
                         Term2, Layout2, [Token|Tokens]).

The purpose of the new argument Tokens is to support multiple, independent expansion rules. The purpose of the arguments Layout1 and Layout2 is to support source-linked debugging of term-expanded code. Each expansion rule should have its unique identifying token Token.

The hook user:goal_expansion/3 is replaced by the following per-module hook:

     M:goal_expansion(Term1, Layout1,
                      Module, Term2, Layout2).

Typically, Module has imported the predicate Term1 from module M. The purpose of the arguments Layout1 and Layout2 is to support source-linked debugging of goal-expanded code.


Send feedback on this subject.