The character escaping facility allows escape sequences to occur within strings and quoted atoms, so that programmers can put non-printable characters in atoms and strings and still be able to see what they are doing. This facility can be switched on and off by the commands:
| ?- prolog_flag(character_escapes, _, on).
| ?- prolog_flag(character_escapes, _, off).
See ref-lps-ove, for a description of prolog_flag/3.
Character escaping is off by default.
Strings or quoted atoms containing the following
escape sequences can occur in
terms obtained by read/[1,2],
compile/1, and so on.
The 0' notation for the integer code of a character is also affected by character escaping.
With character escaping turned on, the only things that can occur in a string or quoted atom are the characters with ASCII codes 9 (horizontal tab), 32 (space), 33 through 126 (non-layout characters), or one of the following escape sequences:
\b
\t
\n
\v
\f
\r
\e
\d
\a
\xCD
CD (hexadecimal number)
\octal string
\^<control char>
\^? is another name for \d.
\layout char
\c
\other
\\ should be used to insert one
backslash
It is an error if an escape sequence or ASCII character that is not defined above occurs in a string or quoted atom. For instance, an ordinary newline in an atom or string is regarded as an error when character escapes are on. This allows the syntax error of a missing closing quote to be caught much earlier, but it has the problem that some old programs will break (which is why character_escapses are off by default).
With character escaping turned on, the escape sequence \' represents
the same character as the sequence '' within a quoted atom, namely
one single quote. Similarly, with character escaping turned on, the
escape sequence \" represents the same character as the sequence
"" within a string, namely one double quote.
The escape sequence \c (c for continue) is useful when
formatting a string for readability.
For example, the atom (A), is equivalent to (B):
'!Ruth \c (A)
Gehrig \c
Cobb \c
Williams!'
'!Ruth Gehrig Cobb Williams!' (B)
The following sequence denotes the integer 9:
0'\t