From jan@swi.psy.uva.nl Wed Apr 18 11:49:33 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f3I9nW300277;
	Wed, 18 Apr 2001 11:49:32 +0200 (MET DST)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.11.2/8.11.2/SuSE Linux 8.11.1-0.5) id f3I9nWn24840;
	Wed, 18 Apr 2001 11:49:32 +0200
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: Pieter Audenaert <Pieter.Audenaert@rug.ac.be>, <prolog@swi.psy.uva.nl>
Subject: Re: [SWIPL] Open stream
Date: Wed, 18 Apr 2001 11:45:03 +0200
X-Mailer: KMail [version 1.0.29.2]
Content-Type: text/plain
References: <Pine.GSO.4.31.0104181128460.6459-100000@allserv.rug.ac.be>
In-Reply-To: <Pine.GSO.4.31.0104181128460.6459-100000@allserv.rug.ac.be>
MIME-Version: 1.0
Message-Id: <01041811493200.23972@gollem>
Content-Transfer-Encoding: 8bit

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

	

