Skip to content

Instantly share code, notes, and snippets.

@takikawa
Created September 4, 2012 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takikawa/3616831 to your computer and use it in GitHub Desktop.
Save takikawa/3616831 to your computer and use it in GitHub Desktop.
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