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 <phi...@philipmcgrath.com <mailto:phi...@philipmcgrath.com>> wrote:

    On Tue, May 18, 2021 at 3:52 PM Sam Tobin-Hochstadt
    <sa...@cs.indiana.edu <mailto:sa...@cs.indiana.edu>> 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 `call-with-continuation-barrier`, right?

    (let* ([conn (connect-to-server)])
      (dynamic-wind
       void
       (λ ()
         (call-with-continuation-barrier
          (λ ()
            (send-message conn "hi"))))
       (λ ()
         (finalize-connection conn))))

I think I don't understand cwcb well enough to get this, but the connect call is not in the pre thunk so it's not guaranteed to happen...right?

The connect will occur once before the dynamic-wind is entered. However, because it is outside dynamic-wind rather than in the pre thunk - connect will /not/ be executed again if the value thunk is reentered.

call-with-continuation-barrier, in effect, puts a sandbox around the contained thunk which prevents continuations captured within the thunk from being invoked outside of it.  IOW, you can jump around /inside/ the thunk, and you can jump out of the thunk ... but if you jump out, you /can't/ jump back in.

As used in the example, the barrier around the value thunk turns dynamic-wind into the moral equivalent of Lisp's unwind-protect: modulo exceptions, pre and value will be executed at most once, and post is guaranteed to be executed regardless of whether pre or value finish.

Hope this helps,
George

--
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 racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/ccf271c7-420e-ded7-ec39-c29bb4f2663d%40comcast.net.

Reply via email to