This built-in predicate reads a single term from the current input stream, the stream is altered. The input stream must be a text stream that was opened for reading.
The Prolog flag console_newline may affect read/1.
see also: char_conversion/2 current_char_conversion/2 current_op/3 op/3 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/2 write_term/3 writeq/1 writeq/2
| Example | |
| read(A). | assume the current input stream has contents: foo(A+B).
test(1). ... A is assigned the value foo(__1 + __2) and the stream is left as: test1(1). ... |
| read(test(O)). | assume the current input stream has contents: test1(1).
test2(2) ... O is assigned the value 1 and read/1 succeeds, and the stream is left as: test2(2) ... |
| Exceptions | |
| the current input stream IS is associated with a binary stream | a permission_error(input, binary_stream, IS) is thrown and IS is substituted by the binary stream |
| the current 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 |