ISO/IEC JTC1 SC22 WG17
Draft for corrected 7.10.5 Writing a term

(see also all documents, Syntax, variable_names)

** Under construction!**

This is the complete subclause 7.10.5 as it should be according to WDCor.3. Removed parts are striked through, added parts are underlined. Line breaks in the original text correspond to the original IS 13211-1:1995 edition.

7.10.5 Writing a term

When a term Term is output using write_term/3 (8.14.2)
the action which is taken is defined by the rules below:
 
a1) If Term is a variable and there is an effective write-option
variable_names(VN_list) and the list VN_list has an element
of the form A = Term with A an atom, then A is output with effective
write-option quoted(false).
 
a) If a2) Else if Term is a variable, a character sequence repre-
senting that variable is output. The sequence begins
with _ (underscore) and the remaining characters are
implementation dependent. During the execution of write_term/3,
the same character sequence
is used for each occurrence of a particular variable in
Term. A
and a different character sequence is used for each
distinct variable in Term.
 
b) If Term is an integer with value N1, a character
sequence representing N1 shall be output. The first
character shall be - if the value of N1 is negative. The
other characters shall be a sequence of decimal digit
chars (6.5.2). The first decimal digit char shall be 0 iff
the value of Term is zero.
 
c) If Term is a float with value F1, a character
sequence representing F1 shall be output. The first
character shall be - if the value of F1 is negative. The
other characters shall be an implementation dependent
sequence of characters which conform to the syntax for
floating point numbers (6.4.5).

If there is an effective write-option quoted(true), then
the characters output shall be such that if they form a
number with value F2 in a term input by read_term/3,
then

F1 = F2
 
d) If Term is an atom then if (1) there is an effective
write-option quoted(true) and (2) the sequence of
characters forming the atom could not be input as a
valid atom without quoting, then Term is output as a
quoted token, else Term is output as the sequence of
characters defined by the syntax for the atom (6.1.2 b,
6.4.2).
 
e) e1) If Term has the form '$VAR'(N) for some pos-
itive
non-negative integer N, and there is an effective write-option
numbervars(true), a variable name as defined in
subclause 7.10.4 is output,
 
g) e2) Else if Term has the form '.'(Head, Tail), and
there is an effective write-option ignore_ops(false),
then Term is output using list notation, that is:
1) [ (open list char) is output.
2) Head is output by recursively applying these
rules. Head is preceded by ( (open char)
and followed by ) (close char), if the term could not be
re-input correctly with the same set of current operators.

3) If Tail has the form '.'(H,T) then , (comma
char) is output, set Head:=H, Tail:=T, and goto (2).
4) If Tail is [] then a closing bracket ] (close list
char) is output,
5) Else a | (head tail separator char) is output,
Tail is output by recursively applying these rules,
Tail is preceded by ( (open char)
and followed by ) (close char), if the term could not be
re-input correctly with the same set of current operators,

and finally, ] (close list char) is output.
 
e3) Else if Term has the form '{}'(Arg), and there is
an effective write-option ignore_ops(false), then
Term is output as a curly bracketed term (6.3.6), that is:
1) { (open curly char) is output
2) Arg is output by recursively applying these rules
3) } (close curly char) is output
 
f) Else if Term has a principal functor which is not
a current operator, or if there is an effective write-
option ignore_ops(true), then the term is output in
canonical form functional notation (6.3.3), that is:
1) The atom of the principal functor is output.
2) ( (open char) is output.
3) Each argument of the term is output by recursively
applying these rules. The argument is preceded by ( (open char)
and followed by ) (close char), if the term could not be
re-input correctly with the same set of current operators.
4) , (comma char) is output between each successive
pair of arguments.
5) ) (close char) is output.
 
h) If Else if Term has a principal functor which is an
operator, and there is an effective write-option
ignore_ops(false), then the term is output in operator
form, that is:
 
1) The atom of the principal functor is output
in front of its argument (prefix operator), between
its arguments (infix operator), or after its argument
(postfix operator). In all cases, a space is output
to separate an operator from its argument(s) if any
ambiguity could otherwise arise.

Operator ',' and '|' are output as , (comma char)
and | (bar char) respectively.

 
2) Each argument of the term is output by recursively
applying these rules. When an An argument is itself
to be output in operator form, it
is preceded by (
(open char) and followed by ) (close char) if: (i) the
principal functor is an operator whose priority is so
high that the term could not be re-input correctly with
same set of current operators, or (ii) the argument is
an atom which is a current operator, or (iii) the
principal functor is output as a prefix operator - and
the argument is a non-negative number, or (iv) the principal
functor is output as a prefix operator - and the
argument is to be output in infix or postfix operator form.
NOTE — A processor may output the floating point value 1.5
as "1.5" or "1.5E+00" or "0.15e1".

Version Control, Validated HTML