Created
March 28, 2020 16:11
-
-
Save 0918nobita/8cef6f7606481a73ea86b30c700d1398 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/base | |
| (require racket/function) | |
| (define k 'bool) ; 継続 | |
| (define continue? #f) | |
| (define (resume) | |
| (set! continue? #t) | |
| (k 'dummy) | |
| (newline)) | |
| (define (suspend escape) | |
| (set! continue? #f) | |
| (set! k (call/cc identity)) | |
| (if continue? #f (escape #f))) | |
| (define-syntax block | |
| (syntax-rules () | |
| [(_ escape proc) (call/cc (λ (escape) proc))])) | |
| (define (proc _) | |
| (block escape | |
| (letrec ([iter | |
| (λ (i) | |
| (display i) | |
| (suspend escape) | |
| (iter (+ i 1)))]) | |
| (iter 0)))) | |
| (set! k proc) | |
| (let () (resume) (displayln "hello!")) | |
| (resume) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment