This built-in predicate reads a single term from an input stream according to the specified values in the read-options list, the stream is altered. The input stream must be a text stream that was opened for reading. The possible read-options are:
If read_options_list is a valid list of read-options then a term is read according to the following rules:
The Prolog flag console_newline may affect read_term/3.
see also: char_conversion/2 current_char_conversion/2 current_op/3 op/3 read/1 read/2 read_term/2 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/2 write_term/3 writeq/1 writeq/2
| Example | |
| read_term(user_in, A, [variables(V), variable_names(VN), singletons(S)]). | assume the input stream 'user_in' has contents: foo(B, C,
B)). test(1). .. after a term was read the values of the variables are: |
| read_term(user_in, A, [variables(V), variable_names(VN)]). | assume the current input stream has contents: test1(1). After
the term was read the values of the variables are: A=test(1) V=__2 VN=__3 |
| Exceptions | |
| the read_options_list is a variable | an instantiation_error exception is thrown |
| the read_options_list is list with an element E which is a variable | an instantiation_error exception is thrown |
| read_options_list is neither a variable nor a list | a type_error(list, Read_options_list) exception is thrown |
| an element E of the read_options_list is neither a variable nor a list | a domain_error(read_option, E) exception is thrown |
| 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, IS) exception is thrown, the variable IS is assigned the incorrect stream_or_alias term |
| stream_or_alias is not associated with an open stream | an existence_error(stream, IS) exception is thrown |
| stream_or_alias is an output stream | a permission_error(input, stream, IS) exception is thrown |
| stream_or_alias is a binary stream | a permission_error(input, binary_stream, IS) is thrown, the variable IS is assigned the stream which was used as the input stream |
| the input stream IS has stream properties end_of_stream(past) and eof_action(error) | a permission_error(input, past_end_of_stream, IS) is thrown and IS is substituted by the stream which was used for reading the term |
| the sequence of tokens cannot be parsed as a term using the current operator table | a syntax_error(A) exception is thrown, the variable A is replaced by an error message of Trinc-Prolog which describes the error |