Create a gist now

Instantly share code, notes, and snippets.

Dynamic wind & call/cc
#lang racket
(define k1 #f)
(define k2 #f)
(call-with-continuation-prompt
(lambda ()
;; this dw will only run twice and not three for
;; the initial run, k1, and then k2
(dynamic-wind
(lambda () (displayln "pre1"))
(lambda ()
;; create an application in continuation
((call/cc
(lambda (k)
(set! k1 k)
(call/cc
(lambda (k)
(set! k2 k)
;; identity function for first run
(lambda (x) x)))))
;; returned in first run
;; sent to k2 after invocation of k1
(lambda (x) 5)))
(lambda () (displayln "post1")))))
(call-with-continuation-prompt
;; invoke k1 and then invoke k2
(lambda () (k1 k2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment