Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-19 Thread George Neuner
Coming late to this ... On 5/19/2021 11:31 AM, David Storrs wrote: On Tue, May 18, 2021 at 4:09 PM Philip McGrath mailto:phi...@philipmcgrath.com>> wrote: On Tue, May 18, 2021 at 3:52 PM Sam Tobin-Hochstadt mailto:sa...@cs.indiana.edu>> wrote: I think the key question is what

Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-19 Thread David Storrs
On Tue, May 18, 2021 at 4:09 PM Philip McGrath wrote: > On Tue, May 18, 2021 at 3:52 PM Sam Tobin-Hochstadt > wrote: > >> I think the key question is what you want to happen if you would need >> to re-run the "pre" thunk, because you re-enter the code via a >> continuation. >> >> In many cases,

Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread Philip McGrath
On Tue, May 18, 2021 at 3:52 PM Sam Tobin-Hochstadt wrote: > I think the key question is what you want to happen if you would need > to re-run the "pre" thunk, because you re-enter the code via a > continuation. > > In many cases, you don't want to support that at all … > Then you can use

Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread Sam Tobin-Hochstadt
I think the key question is what you want to happen if you would need to re-run the "pre" thunk, because you re-enter the code via a continuation. In many cases, you don't want to support that at all, and then it's pretty easy (although you still need mutation): (let* ([conn (connect-to-server)]

Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread David Storrs
Thank you. Is there a way to do it without the mutation? I was hoping to use this for macro generation that simplifies combining with-handlers and dynamic-wind with setup/teardown code. (try [pre (define db (connect-to-db)) (define conn (connect-to-server))] [(send-message conn

Re: [racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread Sam Tobin-Hochstadt
It's not quite as convenient, but here's a version of your program that should work: (let ([conn #f]) (dynamic-wind (lambda () (set! conn (connect-to-server)) (lambda () (send-message conn "foo")) (lambda () (finalize-connection conn Sam On Tue, May 18, 2021 at 2:08 PM David

[racket-users] Sharing scope in setup/cleanup for dynamic-wind?

2021-05-18 Thread David Storrs
dynamic-wind is nice because it guarantees that the pre- and postconditions for a chunk of code will be run regardless of continuation jumps, exceptions, etc. The only issue I have is that the three thunks do not share scope, making it difficult to do setup/teardown workflows. I feel like I