This built-in predicate outputs a term to the current output 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 specified write-options list. The possible values of the write options list are:
The Prolog flags print_double_quotes and expand_backslash may affect write_term/2.
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/2 write_canonical/1 write_canonical/2 write_list/1 write_list/2 write_list_goal/2 write_list_goal/3 write_term/3 writeq/1 writeq/2
| Example | |
| write_term(X=a, [ignore_ops(true)]). | succeeds with empty substitution and the following data was written to the current output stream: =(__1, a) |
| Y=a + '$VAR'(53), write_term(Y, [ignore_ops(true), numbervars(true)]). | assume the current output stream has contents: =(__1, a) and the current output stream is left as: =(__1, a)+a(, B2) |
| Exceptions | |
| the write options list is a variable | an instantiation_error exception is thrown |
| the write options list is neither a variable nor a list | a type_error(list, WriteOptions) exception is thrown |
| an element E of the write options list is a variable | an instantiation_error exception is thrown |
| an element E of the write options list is neither a variable nor a valid write option | a domain_error(write_option, E) exception is thrown |
| the current output stream OS is associated with a binary stream | a permission_error(output, binary_stream, OS) is thrown and OS is substituted by the binary stream |