;; The first thunk passed to `finally` would be called on normal exit ;; and on exit via condition but not when escaping via a ;; continuation. For dealing with the latter, too, you'd need to use ;; dynamic-wind + handle-exceptions instead. (define (dwim-with-input-file path proc) (let ((port (open-input-file path))) (finally (lambda (close-input-port port)) (lambda () (proc port)))))