Hello, I noticed this:
scheme@(guile-user)> (call-with-input-string "hello" (lambda (p) (values 1 2))) $1 = 1 $2 = 2 but: scheme@(guile-user)> (call-with-input-file "hello" (lambda (p) (values 1 2))) $1 = 1 I look up call-with-input-file and I see: (define (call-with-input-file str proc) (let* ((file (open-input-file str)) (ans (proc file))) (close-input-port file) ans)) Now, in Guile 1.8: guile> (let ((a (values 1 2))) a) 1 2 But in Guile 2.0.1: scheme@(guile-user)> (let ((a (values 1 2))) a) $1 = 1 The second one breaks call-with-input-file, but probably both should be errors. Anyway, here is a patch for call-with-input/output-file that avoids the issue. Regards, Daniel From 06f8aea901cd3da68a409a9932757209d91efc40 Mon Sep 17 00:00:00 2001 From: Daniel Llorens <daniel.llor...@bluewin.ch> Date: Mon, 2 May 2011 14:54:20 +0200 Subject: [PATCH] Fix call-with-input-file, call-with-output-file with multiple values * module/ice-9/r4rs.scm: Write call-with-input-file, call-with-input-file in terms of dynamic-wind. --- module/ice-9/r4rs.scm | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-) diff --git a/module/ice-9/r4rs.scm b/module/ice-9/r4rs.scm index 4d3feba..337e196 100644 --- a/module/ice-9/r4rs.scm +++ b/module/ice-9/r4rs.scm @@ -144,10 +144,11 @@ automatically and the value yielded by the procedure is returned. If the procedure does not return, then the port will not be closed automatically unless it is possible to prove that the port will never again be used for a read or write operation." - (let* ((file (open-input-file str)) - (ans (proc file))) - (close-input-port file) - ans)) + (let ((port #f)) + (dynamic-wind + (lambda () (set! port (open-input-file str))) + (lambda () (proc port)) + (lambda () (if port (close-input-port port)))))) (define (call-with-output-file str proc) "PROC should be a procedure of one argument, and STR should be a @@ -160,10 +161,11 @@ automatically and the value yielded by the procedure is returned. If the procedure does not return, then the port will not be closed automatically unless it is possible to prove that the port will never again be used for a read or write operation." - (let* ((file (open-output-file str)) - (ans (proc file))) - (close-output-port file) - ans)) + (let ((port #f)) + (dynamic-wind + (lambda () (set! port (open-output-file str))) + (lambda () (proc port)) + (lambda () (if port (close-output-port port)))))) (define (with-input-from-port port thunk) (let* ((swaports (lambda () (set! port (set-current-input-port port))))) -- 1.7.1