[ Obsolete | Reference Manual | Alphabetic 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.

This built-in predicate is obsolete!

Description

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

If the stream is not a file, the Name argument has different meanings: If it is the user's console, the pseudo file names 'user' or 'error' are returned. If the stream is a string stream, Name returns the current contents of the string stream.

The following table illustrates the predefined symbolic 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
    stdin           user         read    0
    output          user         write   1
    stdout          user         write   1
    warning_output  user         write   1
    log_output      user         write   1
    error           error        write   2
    stderr          error        write   2
    null            null         update  3

Also see set_stream/2 for details on how to assign a symbolic stream name to a physical stream, or to redirect a symbolic stream name.

Modes and Determinism

Fail Conditions

Fails if Stream is not a stream

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

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