Created
September 4, 2012 05:13
-
-
Save takikawa/3616831 to your computer and use it in GitHub Desktop.
Dynamic wind & call/cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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