Subject: Re: [SWIPL] Open stream

From: Jan Wielemaker <[email-masked]>
Date: Wed, 18 Apr 2001 11:45:03 +0200

On Wed, 18 Apr 2001, Pieter Audenaert wrote:
>Hi,
>
>Suppose I have a predicate like
>
>foo:-
>  open('bar','write',Out_Stream),
>  write(Out_Stream,'foobar'),
>  fail.
>
>The file will be opened and the term will be written. But I lose my
>reference to the stream to close it. Will it get closed automatically?
>I don't like the idea of leaving an open stream behind...

On halt or abort.  You can do so yourself by writing a cleanup
routine that uses current_stream/3 or stream_property/2 (ISO) to find
the open streams and close them.

In general however you should program such that the close is
always reached, which implies you also have to watch for exceptions
that can happen if write causes the disk to be full or a write-error
occurrs.

	--- Jan