Created
July 7, 2020 17:14
-
-
Save gengar/55d9e384672be82e352b7e608e695f29 to your computer and use it in GitHub Desktop.
fcontrol/runってこういう理解でOK?
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 | |
(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