[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] valid implementation of call-with-input-file?

On Sun, Aug 19, 2012 at 11:23:03AM +0200, Andy Wingo wrote:
> Hello,
> Is this implementation of call-with-input-file valid?
>   (define (call-with-input-file filename proc)
>     (let ((port (open-input-file filename)))
>       (with-exception-handler
>         (lambda (x)
>           (close-input-port port)
>           x)
>         (lambda ()
>           (call-with-values (lambda () (proc port))
>             (lambda vals
>               (close-input-port port)
>               (apply values vals)))))))
> I think no, due to the language on p52 of the report:
>     If proc does not return, then the
>     port must not be closed automatically unless it is possible
>     to prove that the port will never again be used for a read
>     or write operation.
> I think we should specify that exceptional exits close the port, as the
> above implementation does.

I've argued this point on several occasions before, but nobody listened :(

With the current behavior users will need to remember to wrap each and
every call to call-with-input-file or with-input-from-file that *might*
cause an error (ie, probably ALL of them) in an exception handler.
This is very un-Schemely since it means the default behavior is simply

"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
							-- Donald Knuth

Scheme-reports mailing list