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

close(+Stream)

Closes the stream specified by Stream.

+Stream
Integer or atom.

Description

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

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

When Stream is a logical stream, it is closed and its name no longer refers to any logical stream. If its corresponding physical stream is open, it is closed as well.

When an attempt is made to close a system stream, an error 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 also that the default error handler for the error 196 first resets all system streams connected to the physical stream to their defaults and then closes the physical stream. If the user tries to close the default stream, the error handler just succeeds.

Fail Conditions

None.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
Stream is not instantiated.
(5) Type error
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