[ Term I/O | Reference Manual | Alphabetic Index ]

write(+Stream, ?Term)

The term Term is written on the output stream Stream according to the current operator declarations.
Stream
Stream handle or alias (atom)
Term
Prolog term.

Description

Used to write the term Term on the output stream Stream according to the current operator declarations. Lists and compound terms are only printed up to the nesting depth specified by the (stream-specific or global) print_depth setting (cf. set_stream_property/3, set_flag/2).

write(Term) is equivalent to write_term(Term, [numbervars(true)]).

Note that as usual, the output is buffered, so it may need to be flushed (e.g. explicitly using flush/1).

Note The output of write/1 is not necessarily in a form acceptable to read/1,2.

Modes and Determinism

Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

Exceptions

(4) instantiation fault
Stream is not instantiated.
(5) type error
Stream is not an atom or a stream handle.
(192) illegal stream mode
Stream is not an output steam.
(193) illegal stream specification
Stream is an illegal stream specification.

Examples

Success:
      ?- open(file1,update,s), write(s, X + 2), close(s).
      X = _72
      yes.
      ?- sh('cat file1').
      _72 + 2
      yes.

Error:
      write(S, a(b,c)).          (Error 4).
      write("string", a(b,c)).   (Error 5).
      write(9, X + 2).           (Error 192). % stream not open
      write(atom, X + 2).        (Error 193).


See Also

display / 1, display / 2, get_flag / 2, set_flag / 2, write / 1, writeln / 2, writeq / 1, writeq / 2