Created
May 7, 2013 07:05
-
-
Save ktakashi/5530751 to your computer and use it in GitHub Desktop.
shift rest in R6RS
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
(library (partcont) | |
(export shift reset) | |
(import (rnrs) (srfi :39)) | |
(define *meta-continuation* | |
(make-parameter | |
(lambda value | |
(error "No top-level RESET" value)))) | |
(define-syntax reset | |
(syntax-rules () | |
((reset body ...) | |
(let ((mc (*meta-continuation*))) | |
(call-with-current-continuation | |
(lambda (k) | |
(*meta-continuation* | |
(lambda (value) | |
(*meta-continuation* mc) | |
(k value))) | |
(let-values ((result (begin body ...))) | |
;;** do not beta-substitute!! | |
(apply (*meta-continuation*) result)))))))) | |
(define-syntax shift | |
(syntax-rules () | |
((shift var body ...) | |
(call-with-current-continuation | |
(lambda (k) | |
(let-values ((result (let ((var (lambda value | |
(reset (apply k value))))) | |
body ...))) | |
;;** do not beta-substitute!! | |
(apply (*meta-continuation*) result))))))) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment