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: doco ports verbiage Date: Sun, 15 Jun 2003 10:32:10 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <877k7ow585.fsf@zip.com.au> References: <877k7sm7uq.fsf@zip.com.au> <87smqf8kcr.fsf@zagadka.ping.de> <87u1at7cgk.fsf@zip.com.au> <87k7bp5wj3.fsf@zagadka.ping.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1055637052 20388 80.91.224.249 (15 Jun 2003 00:30:52 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 15 Jun 2003 00:30:52 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jun 15 02:30:48 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 19RLPo-0005IX-01 for ; Sun, 15 Jun 2003 02:30:36 +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 19RLRt-0008HD-MM for guile-devel@m.gmane.org; Sat, 14 Jun 2003 20:32:45 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.20) id 19RLRY-0008BP-IE for guile-devel@gnu.org; Sat, 14 Jun 2003 20:32:24 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.20) id 19RLRW-00087T-Se for guile-devel@gnu.org; Sat, 14 Jun 2003 20:32:23 -0400 Original-Received: from snoopy.pacific.net.au ([61.8.0.36]) by monty-python.gnu.org with esmtp (Exim 4.20) id 19RLRW-00084N-3t for guile-devel@gnu.org; Sat, 14 Jun 2003 20:32:22 -0400 Original-Received: from sunny.pacific.net.au (sunny.pacific.net.au [203.2.228.40]) h5F0WJYd018923 for ; Sun, 15 Jun 2003 10:32:19 +1000 Original-Received: from wisma.pacific.net.au (wisma.pacific.net.au [210.23.129.72]) by sunny.pacific.net.au with ESMTP id h5F0WJQg001179 for ; Sun, 15 Jun 2003 10:32:19 +1000 (EST) Original-Received: from localhost (ppp116.dyn228.pacific.net.au [203.143.228.116]) by wisma.pacific.net.au (8.12.9/8.12.9) with ESMTP id h5F0WGYZ023192 for ; Sun, 15 Jun 2003 10:32:17 +1000 (EST) Original-Received: from gg by localhost with local (Exim 3.35 #1 (Debian)) id 19RLRK-0000wg-00; Sun, 15 Jun 2003 10:32:10 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never In-Reply-To: <87k7bp5wj3.fsf@zagadka.ping.de> (Marius Vollmer's message of "14 Jun 2003 02:32:16 +0200") 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:2543 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:2543 Marius Vollmer writes: > > Or we could stay in Scheme and say it is equivalent to > > (open-file FILENAME "w") Yes, that sounds like the way to go. New effort below, referring to open-input-file and open-output-file, which strike me as natural counterparts to these `with' functions. > and make sure that open-file is documented properly. I guess it already says the contents are removed (truncated) for "w". - Scheme Procedure: call-with-input-file filename proc - Scheme Procedure: call-with-output-file filename proc Open FILENAME for input or output, and call `(PROC port)' with the resulting port. Return the value returned by PROC. FILENAME is opened as per `open-input-file' or `open-output-file' respectively, and an error is signalled if it cannot be opened. When PROC returns, the port is closed. If PROC does not return (eg. if it throws an error), then the port might not be closed automatically, though it will be garbage collected in the usual way if not otherwise referenced. - Scheme Procedure: with-input-from-file filename thunk - Scheme Procedure: with-output-to-file filename thunk - Scheme Procedure: with-error-to-file filename thunk Open FILENAME and call `(THUNK)' with the new port setup as respectively the `current-input-port', `current-output-port', or `current-error-port'. Return the value returned by THUNK. FILENAME is opened as per `open-input-file' or `open-output-file' respectively, and an error is signalled if it cannot be opened. When THUNK returns, the port is closed and the previous setting of the respective current port is restored. The current port setting is managed with `dynamic-wind', so the previous value is restored no matter how THUNK exits (eg. an exception), and if THUNK is re-entered (via a captured continuation) then it's set again to the FILENAME port. The port is closed when THUNK returns normally, but not when exited via an exception or new continuation. This ensures it's still ready for use if THUNK is re-entered by a captured continuation. Of course the port is always garbage collected and closed in the usual way when no longer referenced anywhere. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel