next up previous contents index
Next: Special I/O Up: Input and Output Previous: Character I/O   Contents   Index

Term I/O

read(?Term)

A HiLog term is read from the current or designated input stream, and unified with Term according to the operator declarations in force. (See Section 4.1 for the definition and syntax of HiLog terms). The term must be delimited by a full stop (i.e. a ``.'' followed by a carriage-return, space or tab). Predicate read/1 does not return until a valid HiLog term is successfully read; that is, in the presense of syntax errors read/1 does not fail but continues reading terms until a term with no syntax errors is encountered. If a call to read(Term) causes the end of the current input stream to be reached, variable Term is unified with the term end_of_file. In that case, further calls to read/1 for the same input stream will cause an error failure.

Exceptions:

existence_error
end_of_file is reached before the current term is read.

read(+Stream, ?Term)

read/2 has the same behavior as read/1 but the input stream is explicitly designated using the first argument.

write(?Term)

The HiLog term Term is written to the current output stream, according to the operator declarations in force. Any uninstantiated subterm of term Term is written as an anonymous variable (an underscore followed by a non-negative integer).

All proper HiLog terms (HiLog terms which are not also Prolog terms) are not written in their internal Prolog representation. Predicate write/1 always succeeds without producing an error.

The HiLog terms that are output by write/1 cannot in general be read back using read/1. This happens for two reasons:

Predicate write/1 treats terms of the form '$VAR'(N) specially: it writes 'A' if N=0, 'B' if N=1, $\ldots$, 'Z' if N=25, 'A1' if N=26, etc. Terms of this form are generated by numbervars/[1,3] described in the section Library Utilities in Volume 2.

write(+Stream, ?Term)

write/2 has the same behavior as write/1 but the output stream is explicitly designated using the first argument.

writeln(?Term)

writeln(Term) can be defined as write(Term), nl.

writeln(+Stream,?Term)

writeln(Term) can be defined as write(Stream,Term), nl(Stream).

display(?Term)

The HiLog term Term is displayed on the terminal (standard output stream), according to the operator declarations in force. In other words, display/1 is similar to write/1 but the result is always written on ``userout''. Like write/1, display/1 always succeeds without producing an error. After returning from a call to this predicate, the current output stream remains unchanged.

write_prolog(?Term)
HiLog
This predicate acts as does write/1 except that any HiLog term Term is written as a Prolog term. write_prolog/1 outputs Term according to the operator declarations in force. Because of this, it differs from write_canonical/1 described below, despite the fact that both predicates write HiLog terms as Prolog terms.

write_prolog(+Stream,?Term)
HiLog
write_prolog/2 has the same behavior as write_prolog/1 but the output stream is explicitly designated using the first argument.

writeq(?Term)

Acts as write(Term), but atoms and functors are quoted whenever necessary to make the result acceptable as input to read/1. writeq/1 treats treats terms of the form '$VAR'(N) the same way as write/1, writing A if N= 0, etc.

writeq/1 always succeeds without producing an error.

writeq(+Stream, ?Term)

writeq/2 has the same behavior as writeq/1 but the output stream is explicitly designated using the first argument.

write_canonical(?Term)

This predicate is provided so that the HiLog term Term, if written to a file, can be read back using read/1 regardless of special characters appearing in Term or prevailing operator declarations. Like write_prolog/1, write_canonical/1 writes all proper HiLog terms to the current output stream using the standard Prolog syntax (see Section 4.1 on the standard syntax of HiLog terms). write_canonical/1 also quotes atoms and functors as writeq/1 does, to make them acceptable as input of read/1. Operator declarations are not taken into consideration, and compound terms are therefore always written in the form:


\begin{displaymath}\langle predicate\ name \rangle
(\langle arg_1 \rangle, \ldots,
\langle arg_n \rangle) \end{displaymath}

Unlike writeq/1, write_canonical/1 does not treat terms of the form '$VAR'(N) specially. It writes square bracket lists using '.'/2 and [] (that is, [foo, bar] is written as '.'(foo,'.'(bar,[]))).

read_canonical(-Term)
basics
Reads a term that is in canonical format from the current input stream and returns it in Term. On end-of-file, it returns the atom end_of_file. If it encounters an error, it prints an error message on stderr and returns the atom read_canonical_error. This is significantly faster than read/1, but requires the input to be in canonical form.

write_canonical(+Stream, ?Term)

write_canonical/2 has the same behavior as write_canonical/1 but the output stream is explicitly designated using the first argument.

print(?Term)

This predicate is intended to provide a handle for user-defined pretty-printing. Currently it is defined as write/1.


next up previous contents index
Next: Special I/O Up: Input and Output Previous: Character I/O   Contents   Index
Baoqiu Cui
2000-04-23