Page 217 - DCAP506_ARTIFICIAL_INTELLIGENCE
P. 217

Unit 14: Prolog




          In Prolog, streams for input and output are pointed to by alias names or via a system-defined  Notes
          terms which the Prolog system supplies with the predicateopen/3/4. The alias names are atoms.
          The following table offers an outline of the streams which can be addressed. For addressing,
          either the device name or the alias name can be used. The device name, or driver name, is used
          only on opening a stream. The alias name displays a logical reference to a stream and discovers
          a link among a stream and a name. The name is liberally selectable.
          Stream                  Alias name

          Standard input          user_input
          Standard output         user_output
          Standard error output   user_error
          Keyboard                keyboard

          Screen                  screen
          The following defaults are fixed for the three standard streams:
          Stream                  Default
          Standard input          Keyboard

          Standard output         Screen or window in which Prolog was started
          Standard error output   Screen or window in which Prolog was started and error message
                                  window

          You can also redefine the typical streams when calling Prolog.


                 Example: The file goals.pro is presumed to enclose the following goals:
          Y is 3 + 4.
          append(A, B, [a,b,c,d]).
          atom(A).
          If  you  then call  Prolog and  state the  file as  the input  stream,  these  goals  are  developed
          sequentially. The following output occurs on the screen:
          $ prolog < goals.pro
          Y       = 7

          yes

          A       = []
          B       = [a,b,c,d]
          yes

          no
          $

          When the end of the file is reached, Prolog is finished.
          You  can  utilize  the predicate  stream_copy/2 to  modify the  standard stream  assignments
          throughout a Prolog session.





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