Module term [Preloaded]

Terms can be written to text streams or read from text streams depending on the current oper-ator definitions. It is possible to switch off operator usage by the write option ignore_ops/1. Further during writing variables and atoms are put into quotes when necessary. It is possible to switch on quoting by the write option quoted/1.

Finally terms of the form ‘$VAR’(<number>) are usually recognized and written out as <var>. It is possible to switch on the variable numbering by the write option numbervars/1. The Prolog system also supports '$STR'(<atom>) terms to represent strings and can read or write them as quoted strings.

Table 11: Predefined Write Predicates

Predicate numbervars quoted ignore_ops
write Yes No No
writeq Yes Yes No
write_canonical No Yes Yes

The spacing around operators determined by the operator properties sys_nspl/0 and sys_nspr/0. By default, the operators above level 699 have spacing around them, and the op-erators below and including level 699 do not have spacing around them. With the exception that the operators (';') and (',') do not have a space in the front of them.Examples:

Exampes:
?- X = (a->b;c).
X = (a -> b; c)

?- X = (1+2,3+4).
X = (1+2, 3+4)

If the format option is newline the operator properties sys_tabr/0 and sys_newr/0 are also tak-en into consideration so that the output matches the Prolog coding guidelines as published in [3]. Further the priority option determines whether parentheses are needed around an operator expressions depending on the level of the operator.

When double quotes or back quotes are set to ‘variable’ and quote is true, then variable names are automatically set into the corresponding quotes when necessary. If neither double quotes nor back quotes are set to ‘variable’, then the predicates write_term/[2,3] throw an error if a variable name would need quotes.

The following term input/output predicates are provided:

write(E): [ISO 8.14.2]
write(T, E): [ISO 8.14.2]
The unary predicate writes the term E to the standard output whereby numbering variables. The binary predicate takes an additional text stream sink as argument.
writeq(E): [ISO 8.14.2]
writeq(T, E): [ISO 8.14.2]
The predicate writes the term E to the standard output whereby quoting atoms and variables if necessary. The binary predicate takes an additional text stream sink as argument.
write_canonical(E): [ISO 8.14.2]
write_canonical(T, E): [ISO 8.14.2]
The predicate writes the term E to the standard output whereby quoting atoms and variables if necessary and ignoring operator declarations. The binary predicate takes an additional text stream sink as argument.
write_term(E, O): [ISO 8.14.2]
write_term(T, E, O): [ISO 8.14.2]
The predicate writes the term E to the standard output taking into account the write options O. The ternary predicate takes an additional text stream sink as argument. The following write options are available:
quoted(B): [ISO] If B then functors are quoted if necessary.
numbervars(B): [ISO] If B then compounds ‘$VAR’(I) are written as variables.
ignore_ops(B): [ISO] If B then functors are not interpreted as operators.
variable_names(N): N are the variable names.
context(C): C is the meta-argument specifier.
format(F): F is the write format.
priority(P): P is the write priority.
double_quotes(U): U is the parsing of double quotes.
back_quotes(U): U is the parsing of back quotes.
single_quotes(U): U is the parsing of single quotes.
annotation(A): A is the annotation mode.
source(S): S is the source the term belongs to.
part(N): P is the part that should be written.
Legal context type values are ‘?’ or an integer. The default context type value is ‘?’. Le-gal format values are ‘false’, ‘newline’, ‘navigation’ and ‘true’. The default format value is ‘false’. Legal values for the operator priority are integer values in the range 0 to 1200. The default operator priority is 1200.

Legal annotation values are ‘false’, ‘makedot’, ‘filler’ and ‘true’. The default annotation value is ‘false’. Legal single quotes, double quotes and back quotes values are ‘error’, ‘chars’ [ISO], ‘codes’ [ISO], ‘variable', 'atom' [ISO] and ‘string’. The default quote values are taken from the corresponding Prolog flags. Legal part values are ‘false’, ‘comment’, ‘statement’ and ‘true’. The de-fault part value is ‘true’.
read(E): [ISO 8.14.1]
read(T, E): [ISO 8.14.1]
The unary predicate reads a sentence from the standard input and parses it into a Prolog term. The sentence consists of the tokens up to the first terminating period (“.”). When the sentence only contains filler without a terminating period (“.”) then the predicate succeeds when E unifies with the end_of_file atom. Otherwise the predicate succeeds when E unifies with the parsed term. The binary predicate takes an additional text stream source as argument.
read_term(E, O): [ISO 8.14.1]
read_term(T, E, O): [ISO 8.14.1]
The predicate reads the term E from the standard output taking into account the read options O. The ternary predicate takes an additional text stream source as argument. The following read options are available:
variables(L): [ISO] L are the variables.
variable_names(N): [ISO] N are the variable names.
singletons(S): [ISO] S are the singleton names.
double_quotes(U): U is the parsing of double quotes.
priority(P): P is the read priority.
terminator(T): T is the terminator.
back_quotes(U): U is the parsing of back quotes.
single_quotes(U): U is the parsing of single quotes.
annotation(A): A is the annotation mode.
source(S): S is the source the term belongs to.
line_no(N): N is line number where the term starts.
Legal terminator values are 'period' [ISO], 'end_of_file' and 'none'. The default value is 'period'. Legal single quotes, double quotes and back quotes values are ‘error’, ‘chars’ [ISO], ‘codes’ [ISO], ‘variable’, 'atom' [ISO] and ‘string'. The default values are taken from the corresponding Prolog flags. Legal annotation values are ‘false’, ‘makedot’, ‘filler’ and ‘true’. The default annotation is ‘false’.

The following Prolog flags for term input/output are provided:

char_conversion: [ISO 7.11.2.1]
Legal values are ‘on’ [ISO] and ‘off'’ [ISO]. The flag indicates whether unquoted tokens are character converted. The default value is ‘off’. Currently the value cannot be changed.
double_quotes: [ISO 7.11.2.5]
Legal values are ‘error’, ‘chars’ [ISO], ‘codes’ [ISO], ‘variable’, ‘atom’ [ISO] and ‘string’. The flag indicates how double quoted strings are parsed. The default value is ‘codes’.
back_quotes:
Legal values are ‘error’, ‘chars’, ‘codes’, ‘variable’, ‘atom’ and ‘string’. The flag indicates how back quoted strings are parsed. The default value is ‘error’.
single_quotes:
Legal values are ‘error’, ‘chars’, ‘codes’, ‘variable’, ‘atom’ and ‘string’. The flag indicates how single quoted strings are parsed. The default value is ‘atom’.

The following operator properties for term input/output are provided:

sys_nspl:
The property indicates that no space should be placed in front of the operator. By default, operators have spacing around if and only if they are above level 699. The property can be changed.
sys_nspr:
The property indicates that no space should be placed behind the operator. By default, operators have spacing around if and only if they are above level 699. The property can be changed.
sys_tabr:
The property indicates that the indent behind the operator should be increased. By default, operators increase indent if and only if they are above level 1049. The property can be changed.
sys_newr:
The property indicates that a newline behind the operator should be inserted. By default, operators insert newline if and only if they are above level 949 and below including 1049 or if they are above 1149. The property can be changed.

Kommentare