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 Storrs <[email protected]> wrote:
>
> 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 should be
> able to make this work with nested dynamic-wind or with-handlers but haven't
> been able to get there without losing the guarantee of running. Is there a
> way?
>
> Example of what I'd like to do:
>
> (my-dynamic-wind
> (thunk (define conn (connect-to-server)))
> (thunk (send-message conn "foo"))
> (thunk (finalize-connection conn)))
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CAE8gKodTcogsfeiYKu5iyFbL4H%2Ba3dzuL7rLTfYERD%2BauFD9xQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2BYaP0GV4JppQs%2BpmoOomFskEY%3D7cJ82Ujero7QrzPst1w%40mail.gmail.com.