|Did you know ...||Search Documentation:|
|Character Escape Syntax|
Within quoted atoms (using single quotes:
special characters are represented using escape sequences. An escape
sequence is led in by the backslash (
character. The list of escape sequences is compatible with the ISO
standard but contains some extensions, and the interpretation of
numerically specified characters is slightly more flexible to improve
compatibility. Undefined escape characters raise a
exception.25Up to SWI-Prolog 6.1.9,
undefined escape characters were copied verbatim, i.e., removing the
format('This is a long line that looks better if it was \c split across multiple physical lines in the input')
\c. We advise using
\cor putting the layout before the
, as shown below. Using
\cis supported by various other Prolog implementations and will remain supported by SWI-Prolog. The style shown below is the most compatible solution.26Future versions will interpret
<return> according to ISO.
format('This is a long line that looks better if it was \ split across multiple physical lines in the input')
format('This is a long line that looks better if it was\ split across multiple physical lines in the input')
Note that SWI-Prolog also allows unescaped newlines to appear in quoted material. This is not allowed be the ISO standard, but used to be common practice before.
0'\sto get the character code of the space character. Not ISO.
\is obligatory according to the ISO standard, but optional in SWI-Prolog to enhance compatibility with the older Edinburgh standard. The code
\xa\3emits the character 10 (hexadecimal `a') followed by `3'. Characters specified this way are interpreted as Unicode characters. See also
\xdefines a numeric character code, it doesn't specify the character set in which the character should be interpreted. Second, it is not needed to use the idiosyncratic closing
ISO Prolog syntax.
\uXXXX, but using 8 digits to cover the whole Unicode set.
'\\'is an atom consisting of a single
''''both describe the atom with a single
'\'' == ''''is true.
Character escaping is only available if
current_prolog_flag(character_escapes, true) is active
(default). See current_prolog_flag/2.
Character escapes conflict with writef/2
in two ways:
\40 is interpreted as decimal 40 by writef/2,
but as octal 40 (decimal 32) by
read. Also, the writef/2
\l is illegal. It is advised to use the more widely
predicate instead. If you insist upon using writef/2,
either switch character_escapes
false, or use double
\\, as in