Previous: , Up: ref-syn-cpt   [Contents][Index]


4.1.3.2 Strings As Lists

For convenience, a further notational variant is allowed for lists of integers that correspond to character codes. Lists written in this notation are called strings. E.g.:

"SICStus"

which, by default, denotes exactly the same list as

[83,73,67,83,116,117,115]

The Prolog flag double_quotes can be used to change the way strings are interpreted. The default value of the flag is codes, which implies the above interpretation. If the flag is set to chars, then a string is transformed to a list of character atoms. E.g. with this setting the above string represents the list:

['S','I','C','S',t,u,s]

Finally if double_quotes has the value atom, then the string is made equivalent to the atom formed from its characters: the above sample string is then the same as the atom 'SICStus'.

Please note: Most code assumes that the Prolog flag double_quotes has its default value (codes). Changing this flag is not recommended.

Backslashes in the sequence denote escape sequences (see ref-syn-syn-esc). As for quoted atoms, if a double quote character is included in the sequence, then it must be escaped, e.g. "can\"t".

The built-in predicates that print terms (see ref-iou-tou) do not use string syntax even if they could.

The characters that are allowed to occur within double quotes are restricted to a subset of Unicode; see ref-syn-syn-tok.


Send feedback on this subject.