stream_property(?stream, ?stream_property) [ISO]

With stream_property/2 it is possible to enumerate all open streams together with all of their properties. This predicate is re-executable as long as there are streams and properties of streams still to enumerate. The standard Prolog properties enumerated are:

Trinc-Prolog stream properties

The following stream properties are not part of ISO Prolog standard:

see also: at_end_of_stream/0 at_end_of_stream/1 close/1 close/2 close_user_streams/0 current_input/1 current_output/1 flush_output/0 flush_output/1 open/3 open/4 prolog I/O set_input/1 set_output/1 set_stream_position/2 set_stream_property/2

Example
open('c:\\temp\\file.txt', write, S),
stream_property(S, file_name(N)),
close(S), !.
this example opens an output stream, then the filename of the stream is determined by using stream_property/2 and the stream is closed. The cut is to prevent stream_property/2 for finding more solutions.
stream_property(A, S). the following solutions are generated if the only open streams are the standard input and output streams:

A=$stream(2)
S=end_of_stream(at)

A=$stream(2)
S=output

A=$stream(2)
S=mode(append)

A=$stream(2)
S=eof_action(reset)

A=$stream(2)
S=alias(user_output)

A=$stream(2)
S=reposition(false)

A=$stream(2)
S=type(text)

A=$stream(1)
S=end_of_stream(at)

A=$stream(1)
S=input

A=$stream(1)
S=mode(read)

A=$stream(1)
S=eof_action(reset)

A=$stream(1)
S=alias(user_input)

A=$stream(1)
S=reposition(false)

A=$stream(1)
S=type(text)
no
stream_property(A, alias(S)). for each open stream the value of the property alias/1 was unified with S, the solutions generated for the standard streams are:

A=$stream(2)
S=user_output

A=$stream(1)
S=user_input
no

 

Exceptions  
stream is neither a variable nor a stream term a domain_error(stream, Stream) exception is thrown, the variable Stream is assigned the incorrect stream term
stream_property is neither a variable nor a valid stream property a domain_error(stream_property, Stream_property) exception is thrown

 

 

info@trinc-prolog.com