Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Dynamic wind & call/cc

View gist:3616831
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#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
Something went wrong with that request. Please try again.