- Reference manual
- The SWI-Prolog syntax
- Reference manual
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.24Up to SWI-Prolog 6.1.9,
undefined escape characters were copied verbatim, i.e., removing the
- Alert character. Normally the ASCII character 7 (beep).
- Backspace character.
- No output. All input characters up to but not including the first
non-layout character are skipped. This allows for the specification of
pretty-looking long lines. Not supported by ISO. Example:
format('This is a long line that looks better if it was \c split across multiple physical lines in the input')
- When in ISO mode (see the Prolog flag iso),
only skip this sequence. In native mode, white space that follows the
newline is skipped as well and a warning is printed, indicating that
this construct is deprecated and advising to use
\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.25Future 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')
- Escape character (ASCII 27). Not ISO, but widely supported.
- Form-feed character.
- Next-line character.
- Carriage-return only (i.e., go back to the start of the line).
- Space character. Intended to allow writing
0'\sto get the character code of the space character. Not ISO.
- Horizontal tab character.
- Vertical tab character (ASCII 11).
- Hexadecimal specification of a character. The closing
\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
- Unicode character specification where the character is specified using
exactly 4 hexadecimal digits. This is an extension to the ISO
standard, fixing two problems. First, where
\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.
- Same as
\uXXXX, but using 8 digits to cover the whole Unicode set.
- Octal character specification. The rules and remarks for hexadecimal specifications apply to octal specifications as well.
- Escapes the backslash itself. Thus,
'\\'is an atom consisting of a single
- Single quote. Note that
''''both describe the atom with a single
'\'' == ''''is true.
- Double quote.
- Back quote.
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