
close(+Stream)

   Closes the stream specified by Stream.



Arguments
   Stream              Integer or atom.

Type
   Stream I/O

Description
   Used to close a stream.  Stream can be a symbolic stream name or a
   physical stream number.


   When Stream is a physical stream, it is closed, but all symbolic streams
   associated to it still refer to it until they are either closed as well
   or redirected to other physical streams.  As long as there are some
   symbolic stream names associated to a physical stream, the physical
   stream cannot be reused for other communication channels.


   When Stream is a symbolic stream name, it gets detached from the
   corresponding physical stream, and the physical stream is closed
   (unless it was already closed).


   When an attempt is made to close a system stream, event 196 is raised.
   To close a physical stream connected with a system stream it is
   therefore advisable to redirect the system stream to another physical
   stream.  Note however, that the default handler for the event 196
   first resets all system streams connected to the physical stream to
   their defaults and then closes the physical stream.  Attempts to close
   the default physical stream of a system stream are ignored.




Modes and Determinism
   close(+) is det

Exceptions
     4 --- Stream is not instantiated.
     5 --- Stream is instantiated, but not to an integer or an atom.
   172 --- File specified by stream number Stream is not open.
   193 --- Stream is an illegal stream specification.
   196 --- Trying to close a system stream.

Examples
   
Success:
      open(file1,write,s),write(s, a(b,c)),close(s).

      [eclipse]: open(junk, write, a), set_stream(b, a),
                get_stream(a, S).

      S = 5
      yes.
      [eclipse]: close(a), open(junk1, write, X).

      X = 6       % 5 is not reused because b still points to it
      yes.
      [eclipse]: close(b), open(junk2, write, Y).

      Y = 5       % now 5 can be reused
      yes.


Error:
      close(Stream).         (Error 4).
      close("4").            (Error 5).
      close(10).             (Error 172).
      close(nostream).       (Error 193).
      close(null).           (Error 196).





See Also
   open / 3, open / 4, set_stream / 2
