Skip to content

Instantly share code, notes, and snippets.

@gengar
Created July 7, 2020 17:14
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 gengar/55d9e384672be82e352b7e608e695f29 to your computer and use it in GitHub Desktop.
Save gengar/55d9e384672be82e352b7e608e695f29 to your computer and use it in GitHub Desktop.
fcontrol/runってこういう理解でOK?
#lang racket
(require racket/control)
(define (call-with-run thunk proc)
(call/prompt thunk
(default-continuation-prompt-tag)
proc))
(define-syntax run
(syntax-rules ()
((_ expr proc)
(call-with-run (lambda () expr)
proc))))
(define (fctrl val)
(call/comp
(lambda (cont)
(abort/cc (default-continuation-prompt-tag)
val cont))))
(run (+ 2 (fctrl 5))
(lambda (v k)
(k v)))
;; => 7
(run (+ 2 (fctrl 5))
(lambda (v k)
v))
;; => 5
(run (+ 100 (fctrl (+ 10 (fctrl 1))))
(lambda (v k)
(run (k (+ v v v))
(lambda (v k) (k (k v))))))
;; => 213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment