Page 218 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 218

Artificial Intelligence




                    Notes          14.10.1 Input/Output using  Current  Streams

                                   Input/output predicates  in which no stream is mentioned address the current streams. The
                                   predicate listing/0/1 also sends its outputs to the existing output stream. The Prolog system
                                   concerns error messages on the existing error stream.
                                   When the Prolog system is begin, the corresponding standard streams are first opened, i.e.
                                   Stream              Alias             Default
                                   Current input       current_input     user_input (standard input)

                                   Current output      current_output    user_output (standard output)
                                   Current error output  current_error   user_error (standard error output)
                                   You can point to the current streams by their alias names in input/output predicates which need
                                   a stream to be mentioned.
                                   You can query or modify the settings for the current streams with the following predicates:
                                   Predicate           Purpose

                                   current_input(?Stream)  Query current input stream
                                   set_input(@Stream)  Set current input stream
                                   see(@Stream)        Set and if required, open current input stream
                                   seeing(?Stream)     Query current input stream
                                   seen                Reset current input stream to user_input and if required, close the first
                                                       stream
                                   current_output(?Stream) Query current output stream
                                   set_output(@Stream)  Set current output stream

                                   tell(@Stream)       Set and if required, open current output stream
                                   telling(?Stream)    Query current output stream
                                   told                Reset current output stream to user_output and if required, close the
                                                       first stream
                                   current_error(?Stream)  Query current error stream
                                   set_error(@Stream)  Set current error stream

                                   error_tell(@Stream)  Set and if required, open current error stream
                                   error_telling(?Stream)  Query current error stream
                                   error_told          Reset current error stream to user_error and if required, close the first
                                                       stream
                                   When you announce a file as the current input/output stream, you should primarily open it
                                   with the predicate open/3/4 and then describe it as the current input/output stream with one of
                                   the above predicates. If you desire to state a pipe as the current input/output stream, you should
                                   first produce it with unix_make_pipe/1 and open it with open/3/4. Then you define the pipe as
                                   the existing input/output stream.
                                   With the following predicates, input is utilizing the current input stream and output is utilizing
                                   the current output stream.




          212                               LOVELY PROFESSIONAL UNIVERSITY
   213   214   215   216   217   218   219   220   221   222   223