[Scheme-reports] valid implementation of call-with-input-file? Andy Wingo (19 Aug 2012 09:26 UTC)

[Scheme-reports] valid implementation of call-with-input-file? Andy Wingo 19 Aug 2012 09:23 UTC

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.

Andy
--
http://wingolog.org/

_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports