read_term(?term, +read_options_list) [ISO]

This built-in predicate reads a single term from the current 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/2.

see also: char_conversion/2 current_char_conversion/2 current_op/3 op/3 read/1 read/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_term(A, [variables(V), variable_names(VN), singletons(S)]). assume the current input stream has contents: foo(B, C, B)). test(1). ..

after a term was read the values of the variables are:
A=foo(__5, __6, __5)
V=[_01, _02]
VN=[('B' = _01), ('C' = _02)]
S=['C' = _02]

read_term(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
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

 

 

info@trinc-prolog.com