Skip to content

Instantly share code, notes, and snippets.

@0918nobita
Created March 28, 2020 16:11
Show Gist options
  • Select an option

  • Save 0918nobita/8cef6f7606481a73ea86b30c700d1398 to your computer and use it in GitHub Desktop.

Select an option

Save 0918nobita/8cef6f7606481a73ea86b30c700d1398 to your computer and use it in GitHub Desktop.
#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