From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: documentation.scm close files Date: Thu, 22 May 2003 08:40:09 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87znlfj54m.fsf@zip.com.au> References: <87smrqxt3b.fsf@zip.com.au> <878yt55od2.fsf@zagadka.ping.de> <878yt3yig4.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1053559041 13120 80.91.224.249 (21 May 2003 23:17:21 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 21 May 2003 23:17:21 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu May 22 01:17:18 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 19Icph-0003PD-00 for ; Thu, 22 May 2003 01:17:18 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.20) id 19Ichu-0002TF-7g for guile-devel@m.gmane.org; Wed, 21 May 2003 19:09:14 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19Icay-0001VG-5S for guile-devel@gnu.org; Wed, 21 May 2003 19:02:04 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19IcZ3-0001Do-Jd for guile-devel@gnu.org; Wed, 21 May 2003 19:00:37 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19IcG7-0006X1-OK for guile-devel@gnu.org; Wed, 21 May 2003 18:40:32 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) h4LMeIxh005571 for ; Thu, 22 May 2003 08:40:18 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h4LMeIQg005278 for ; Thu, 22 May 2003 08:40:18 +1000 (EST) Original-Received: from localhost (ppp119.dyn228.pacific.net.au [203.143.228.119]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h4LMeFYZ020073 for ; Thu, 22 May 2003 08:40:16 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19IcFl-0008Ra-00; Thu, 22 May 2003 08:40:09 +1000 Original-To: guile-devel@gnu.org User-Agent: Gnus/5.090019 (Oort Gnus v0.19) Emacs/21.2 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:2416 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2416 I wrote: > > I'm thinking to add some words to the manual to say why it's good to > close explicitly, As threatened, but in the form of a revision of the "Ports" node. The first three paras are existing words slightly warmed-over, the rest is new. Ports ===== Sequential input/output in Scheme is represented by operations on a "port". This chapter explains the operations that Guile provides for working with ports. Ports are created by opening, for instance `open-file' for a file (*note File Ports::). Characters can be read from an input port and written to an output port, or both on an input/output port. A port can be closed (*note Closing::) when no longer required, after which any attempt to read or write is an error. The formal definition of a port is very generic: an input port is simply "an object which can deliver characters on demand," and an output port is "an object which can accept characters." Because this definition is so loose, it is easy to write functions that simulate ports in software. "Soft ports" and "string ports" are two interesting and powerful examples of this technique. (*note Soft Ports::, and *Note String Ports::.) Ports are garbage collected in the usual way (*note Memory Management::), and will be closed at that time if not already closed. In this case any errors occuring in the close will not be reported. Usually a program will want to explicitly close so as to be sure all its operations have been successful. Of course if a program has abandoned something due to an error or other condition then closing problems are probably not of interest. It is strongly recommended that file ports be explicitly closed when no longer required. Most systems have limits on how many files can be open, both on a per-process and a system-wide basis. A program that uses many files should take care not to to upset its own or other program's operations by hitting those limits. The same applies to similar system resources such as pipes and sockets. If program flow means it's hard to be certain when to close, then an acceptable substitute may be to call `gc' at suitable times to pick up unreferenced ports. Note that when a system limit is encountered Guile makes no attempt to automatically garbage collect and retry. There would be little value in doing so, since it would remove just one of many problems for a program trying to operate near system limits all the time. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel