[Up] [Contents] [Index] [Summary]

2.12.1.1 Character Escape Syntax

Within quoted atoms (using single quotes: '<atom>' special characters are represented using escape-sequences. An escape sequence is lead in by the backslash (\) character. The list of escape sequences is compatible with the ISO standard, but contains one extension and the interpretation of numerically specified characters is slightly more flexible to improve compatibility.

\a
Alert character. Normally the ASCII character 7 (beep).

\b
Backspace character.

\c
No output. All input characters upto but not including the first non-layout character are skipped. This allows for the specification of pretty-looking long lines. For compatibility with Quintus Prolog. Nor supported by ISO. Example: format('This is a long line that would look better if it was \c split across multiple physical lines in the input')

\<RETURN>
No output. Skips input till the next non-layout character or to the end of the next line. Same intention as \c but ISO compatible.

\f
Form-feed character.

\n
Next-line character.

\r
Carriage-return only (i.e. go back to the start of the line).

\t
Horizontal tab-character.

\v
Vertical tab-character (ASCII 11).

\x23
Hexadecimal specification of a character. 23 is just an example. The `x' may be followed by a maximum of 2 hexadecimal digits. The closing \ is optional. The code \xa\3 emits the character 10 (hexadecimal `a') followed by `3'. The code \x201 emits 32 (hexadecimal `20') followed by `1'. According to ISO, the closing \ is obligatory and the number of digits is unlimited. The SWI-Prolog definition allows for ISO compatible specification, but is compatible with other implementations.

\40
Octal character specification. The rules and remarks for hexadecimal specifications apply to octal specifications too, but the maximum allowed number of octal digits is 3.

\<character>
Any character immediately preceded by a \ is copied verbatim. Thus, '\\' is an atom consisting of a single \ and '\'' and '''' both describe the atom with a single '.

Character escaping is only available if the feature(character_escapes, true) is active (default). See feature/2. Character escapes conflict with writef/2 in two ways: \40 is interpreted as decimal 40 by writef/2, but character escapes handling by read has already interpreted as 32 (40 octal). Also, \l is translated to a single `l'. Double the \ (e.g. \\, use the above escape sequences or use format/2.