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, 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, the string is made equivalent to the atom formed from its characters: the above sample string is then the same as the atom 'SICStus'.

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 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.


Send feedback on this subject.