[plt-scheme] SXML for R6RS [was: R6RS Interoperability]

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Jul 9 09:18:08 EDT 2008

At Wed, 09 Jul 2008 05:58:51 -0700, Derick Eddington wrote:
> I think the situation you show above is okay because:
> 
> R6RS says of `with-input-from-file': "During the dynamic extent of the
> call to [with-input-from-file's] thunk, the obtained port is made the
> value returned by [the] current-input-port [procedure]; the previous
> default [value is] reinstated when the dynamic extent is exited.  When
> thunk returns, the port is closed automatically.  [...]  If an escape
> procedure is used to escape back into the call to thunk after thunk is
> returned, the behavior is unspecified."  And similarly for the other
> `call-with-' procedures -- they only close their port if/when their
> `proc' returns.
> 
> R6RS says `guard' will re-raise "within the dynamic environment of the
> original call to raise except that the current exception handler is that
> of the guard expression".  
> 
> So, when control escapes to the `guard' implicit cond, the "foo" port
> will not be closed and the previous value of `current-input-port' will
> be reinstated.  When `guard' re-enters the dynamic environment of the
> original call to raise to re-raise the unhandled non-&serious, this
> dynamic environment includes that of (with-input-from-file "foo" ---)
> so `current-input-port' will be reset to the "foo" port. 

I now see that `with-input-form-file' doesn't say what happens if
control *escapes* from the call. The specification of
`call-with-input-file' is more explicit about what happens if you
escape (i.e., the port is not closed), and so I took the
`with-input-from-file' specification to allow closing the port on
escape.

Anyway --- nevermind `with-input-form-file' and `call-with-input-file';
I really wanted to get at `dynamic-wind' behavior. Since the
`with-input-from-file' shortcut didn't work, let's go there directly.

Suppose that you actually want ports to be closed when control escapes
(for any reason), so you write

 (define (call-with-input-file* file proc)
   (let ([p #f])
     (dynamic-wind
       (lambda () (set! p (open-input-file file)))
       (lambda () (proc p))
       (lambda () (close-input-port p) (set! p #f)))))

and use that, instead. Then, doesn't my objection about `ssax:warn' and
`guard' hold?


Matthew



Posted on the users mailing list.