This built-in predicate outputs a term to a stream. The output stream must be a text stream that was opened for writing or appending data. The data is written in a form defined by the write-options list: [numbervars(true), quoted(false), ignore_ops(false)].
The Prolog flags print_double_quotes and expand_backslash may affect write/2. The single quotes of an atom that was enclosed by single quotes are not written to the output stream. Use write_term/2 to specify that single quotes must be written to the current output stream.
see also: char_conversion/2 current_char_conversion/2 current_op/3 op/3 read/1 read/2 read_term/2 read_term/3 write/1 write_canonical/1 write_canonical/2 write_list/1 write_list/2 write_list_goal/2 write_list_goal/3 write_term/2 write_term/3 writeq/1 writeq/2
| Example | |
| write(user_out, X=a). | succeeds with empty substitution and the following data was
written to the ouput stream 'user_out': __1 = 1 ('__1' is how Trinc-Prolog writes an empty variable) |
| write(user_out, '$VAR'(51)). | assume the output stream 'user_out' has contents: __1 = 1 and the output stream 'user_out' is left as: __1 = 1Z1 |
| write('.'). | succeeds and a single dot character is written to the current output stream |
| Exceptions | |
| stream_or_alias is a variable | an instantiation_error exception is thrown |
| stream_or_alias is neither a variable nor a stream term nor an alias | a domain_error(stream_or_alias, Stream) exception is thrown, the variable Stream is assigned the incorrect stream_or_alias term |
| stream_or_alias is not associated with an open stream | an existence_error(stream, Stream) exception is thrown |
| stream_or_alias is an input stream | a permission_error(output, stream, Stream) exception is thrown |
| stream_or_alias is a binary stream | a permission_error(output, binary_stream, OutputStream) is thrown, the variable OutputStream is assigned the stream which was used as the output stream |