[ ECLiPSe Stream I/O built-in.|Group Index| Full Index]

current_stream(?Name, ?Mode, ?Stream)

Succeeds if there is currently an open stream Stream open to the file Name in the mode Mode. This predicate is obsolete, use current_stream/1 and get_stream_info/3 instead.

?Name
Filename (atom or string), contents of string stream (string) or variable.
?Mode
One of the atoms read, write, update, string or a variable.
?Stream
Physical stream number (integer), or a variable.

Description

Unifies Name with the filename and Mode with the mode of the stream Stream. If Stream is a variable, it is bound to all open streams on backtracking.

Also used to return the string associated with a string stream.

The following table illustrates the predefined logical system streams with the name, mode, and initial physical stream number that they are initially assigned to.

    Logical         Name         Mode    Number
    input           user         read    0
    output          user         write   1
    error           error        write   2
    toplevel_input  user         read    0
    toplevel_output user         write   1
    answer_output   user         write   1
    debug_input     debug_input  read    3
    debug_output    user         write   1
    null            null         update  4
There are four other predefined logical streams:

    Logical Name   Mode   Number
    stdin   user   read   0
    stdout  user   write  1
    stderr  error  write  2
    user    user   read   0
    user    user   write  1
The first three of these are UNIX standard streams. The last stream user provides compatibility with other Prolog systems. When using user, it should be possible to decide if an input or output stream was meant.

Each of the above input streams has its own prompt which is printed on the specified output stream whenever new input is required. See set_prompt/3 for details on how to change this prompt.

Also see set_stream/2 for details on how to assign a logical stream to a physical stream.

Fail Conditions

Fails if Stream is not a stream open to the file Name in the mode Mode.

Resatisfiable

Yes.

Exceptions

(5) Type error
Name is instantiated, but not to an atom or a string.
(5) Type error
Mode is not an atom.
(5) Type error
Stream is instantiated, but not to an atom or an integer.

Examples


Success:
      current_stream(Name,Mode,Stream). % returns all
                                        %   open streams.

      [eclipse]: current_stream(error,Mode,Stream).
      Mode = write
      Stream = 2      More? (;)
      yes.

      [eclipse]: open(file,update,s), current_stream(file,M,s).
      M = update
      yes.

      [eclipse]: open(F,string(10),f), writeln(f, "bigstring"),
      > current_stream(Data,M,f).
      F = "bigstring\n"
      Data = "bigstring\n"
      M = string
      yes.

Fail:
      open(file,update,f), current_stream("file",M,f).
      current_stream(X,no,Y).

Error:
      current_stream(12,Mode,String).     (Error 5).


See Also

open / 3, open / 4, current_stream / 1, get_stream_info / 3