racket/control: Racketize & remove trailing whitespace

original commit: ed9c612cae3ac53984445fbe6731ca0870915932
This commit is contained in:
Asumu Takikawa 2012-06-21 15:55:43 -04:00
parent 9b7e9c5feb
commit 3f831d6f4b

View File

@ -1,8 +1,8 @@
(module control racket/base #lang racket/base
(require (for-syntax racket/base)) (require (for-syntax racket/base))
(provide call/prompt call/comp abort/cc (provide call/prompt call/comp abort/cc
abort abort
@ -22,25 +22,25 @@
new-prompt set cupto) new-prompt set cupto)
;; ---------------------------------------- ;; ----------------------------------------
(define call/prompt call-with-continuation-prompt) (define call/prompt call-with-continuation-prompt)
(define call/comp call-with-composable-continuation) (define call/comp call-with-composable-continuation)
(define abort/cc abort-current-continuation) (define abort/cc abort-current-continuation)
;; ---------------------------------------- ;; ----------------------------------------
(define (abort . vals) (define (abort . vals)
(abort-current-continuation (abort-current-continuation
(default-continuation-prompt-tag) (default-continuation-prompt-tag)
(lambda () (apply values vals)))) (lambda () (apply values vals))))
;; ---------------------------------------- ;; ----------------------------------------
;; Sitaram, PLDI'93 ;; Sitaram, PLDI'93
;; The `%' here is compable with Sitaram & Felleisen, LSC'90, ;; The `%' here is compable with Sitaram & Felleisen, LSC'90,
;; since we make the handler optional. ;; since we make the handler optional.
(define (fcontrol f #:tag [prompt-tag (default-continuation-prompt-tag)]) (define (fcontrol f #:tag [prompt-tag (default-continuation-prompt-tag)])
(call-with-composable-continuation (call-with-composable-continuation
(lambda (k) (lambda (k)
(abort-current-continuation (abort-current-continuation
@ -48,7 +48,7 @@
f f
k)))) k))))
(define-syntax % (define-syntax %
(syntax-rules () (syntax-rules ()
[(_ expr handler #:tag prompt-tag) [(_ expr handler #:tag prompt-tag)
(call-with-continuation-prompt (call-with-continuation-prompt
@ -64,19 +64,19 @@
(call-with-continuation-prompt (call-with-continuation-prompt
(lambda () expr))])) (lambda () expr))]))
;; ---------------------------------------- ;; ----------------------------------------
;; Predecessors of Sitaram, PLDI'93 ;; Predecessors of Sitaram, PLDI'93
;; Felleisen, Wand, Friedman, & Duba, LFP'88 ;; Felleisen, Wand, Friedman, & Duba, LFP'88
;; Instead of `#', we use `prompt' as in Felleisen, POPL'88 ;; Instead of `#', we use `prompt' as in Felleisen, POPL'88
;; (where `control' is called `F') ;; (where `control' is called `F')
;; See also Sitaram and Felleisen, LSC'90 ;; See also Sitaram and Felleisen, LSC'90
;; Helpder function: abort-current-continuation/keep-prompt is ;; Helpder function: abort-current-continuation/keep-prompt is
;; like abort-current-continuation, but it always leaves the ;; like abort-current-continuation, but it always leaves the
;; prompt in place, independent of the prompt's handler. ;; prompt in place, independent of the prompt's handler.
;; This is possible via call/cc (i.e., it must be possible ;; This is possible via call/cc (i.e., it must be possible
;; to abort and keep a prompt, because call/cc needs it). ;; to abort and keep a prompt, because call/cc needs it).
(define (abort-current-continuation/keep-prompt tag thunk) (define (abort-current-continuation/keep-prompt tag thunk)
((call-with-continuation-prompt ((call-with-continuation-prompt
(lambda () (lambda ()
((call-with-current-continuation ((call-with-current-continuation
@ -85,11 +85,11 @@
tag) tag)
thunk)) thunk))
;; call-with-control, parameterized over whether to keep the ;; call-with-control, parameterized over whether to keep the
;; prompt (if the prompt's handler gives us the option of ;; prompt (if the prompt's handler gives us the option of
;; removing it). The generated function is the same ;; removing it). The generated function is the same
;; as fcontrol when `abort-cc' is `abort-current-continuation'. ;; as fcontrol when `abort-cc' is `abort-current-continuation'.
(define (make-call-with-control abort-cc) (define (make-call-with-control abort-cc)
;; Uses call/cc to always keep the enclosing prompt. ;; Uses call/cc to always keep the enclosing prompt.
(letrec ([call-with-control (letrec ([call-with-control
(case-lambda (case-lambda
@ -103,10 +103,10 @@
tag)])]) tag)])])
call-with-control)) call-with-control))
(define call-with-control (define call-with-control
(make-call-with-control abort-current-continuation/keep-prompt)) (make-call-with-control abort-current-continuation/keep-prompt))
(define-syntax define-control-macros (define-syntax define-control-macros
(syntax-rules () (syntax-rules ()
[(_ control control-at call-with-control) [(_ control control-at call-with-control)
(begin (begin
@ -121,9 +121,9 @@
(identifier? #'id) (identifier? #'id)
#'(call-with-control (lambda (id) expr0 expr (... ...)) tag)])))])) #'(call-with-control (lambda (id) expr0 expr (... ...)) tag)])))]))
(define-control-macros control control-at call-with-control) (define-control-macros control control-at call-with-control)
(define-syntax define-prompt-macros (define-syntax define-prompt-macros
(syntax-rules () (syntax-rules ()
[(_ prompt prompt-at call-with-prompt) [(_ prompt prompt-at call-with-prompt)
(begin (begin
@ -136,15 +136,15 @@
[(prompt-at tag expr0 expr (... ...)) [(prompt-at tag expr0 expr (... ...))
(call-with-prompt (lambda () expr0 expr (... ...)) tag)])))])) (call-with-prompt (lambda () expr0 expr (... ...)) tag)])))]))
(define-prompt-macros prompt prompt-at call-with-continuation-prompt) (define-prompt-macros prompt prompt-at call-with-continuation-prompt)
;; ---------------------------------------- ;; ----------------------------------------
;; Danvy & Filinski, LFP'90 ;; Danvy & Filinski, LFP'90
;; call-with-shift, parameterized over whether to keep the prompt ;; call-with-shift, parameterized over whether to keep the prompt
;; (if the prompt's handler gives us the option of removing it), ;; (if the prompt's handler gives us the option of removing it),
;; and whether the new one is removable: ;; and whether the new one is removable:
(define (make-call-with-shift abort-cc inserted-handler) (define (make-call-with-shift abort-cc inserted-handler)
(letrec ([call-with-shift (letrec ([call-with-shift
(case-lambda (case-lambda
[(f) (call-with-shift f (default-continuation-prompt-tag))] [(f) (call-with-shift f (default-continuation-prompt-tag))]
@ -163,58 +163,58 @@
tag)])]) tag)])])
call-with-shift)) call-with-shift))
(define call-with-shift (define call-with-shift
(make-call-with-shift abort-current-continuation/keep-prompt #f)) (make-call-with-shift abort-current-continuation/keep-prompt #f))
(define-control-macros shift shift-at call-with-shift) (define-control-macros shift shift-at call-with-shift)
(define-prompt-macros reset reset-at call-with-continuation-prompt) (define-prompt-macros reset reset-at call-with-continuation-prompt)
;; ---------------------------------------- ;; ----------------------------------------
;; Shan, SCHEME'04 ;; Shan, SCHEME'04
;; Kiselyov, Indiana CS TR-611, 2005 ;; Kiselyov, Indiana CS TR-611, 2005
;; ;;
;; The `control0' and `shift0' here are closer to Kiselyov, in that ;; The `control0' and `shift0' here are closer to Kiselyov, in that
;; `control0' and `shift0' only behave as in Shan when paired with ;; `control0' and `shift0' only behave as in Shan when paired with
;; `prompt0' or `reset0' (which are two names for the same thing). ;; `prompt0' or `reset0' (which are two names for the same thing).
;; When paired with `prompt' or `reset' (again, the same thing), ;; When paired with `prompt' or `reset' (again, the same thing),
;; they act like `control' and `shift'. ;; they act like `control' and `shift'.
;; ;;
;; This difference is intentional. The programmer that inserts a ;; This difference is intentional. The programmer that inserts a
;; prompt should choose whether the current continuation is visible ;; prompt should choose whether the current continuation is visible
;; or not. Note, also, that `control' and `shift' work whether ;; or not. Note, also, that `control' and `shift' work whether
;; they're paired with `prompt'/`reset' or `prompt0'/`reset0'. ;; they're paired with `prompt'/`reset' or `prompt0'/`reset0'.
(define call-with-control0 (define call-with-control0
;; Uses abort-current-continuation, so that the prompt ;; Uses abort-current-continuation, so that the prompt
;; is removed --- if the prompt is willing to be removed. ;; is removed --- if the prompt is willing to be removed.
(make-call-with-control abort-current-continuation)) (make-call-with-control abort-current-continuation))
(define call-with-shift0 (define call-with-shift0
;; Uses abort-current-continuation, so that the prompt ;; Uses abort-current-continuation, so that the prompt
;; is removed --- if the prompt is willing to be removed. ;; is removed --- if the prompt is willing to be removed.
;; The prompt installed with the captured continuation is ;; The prompt installed with the captured continuation is
;; itself willing to be removed. ;; itself willing to be removed.
(make-call-with-shift abort-current-continuation (lambda (thunk) (thunk)))) (make-call-with-shift abort-current-continuation (lambda (thunk) (thunk))))
(define-control-macros control0 control0-at call-with-control0) (define-control-macros control0 control0-at call-with-control0)
(define-control-macros shift0 shift0-at call-with-shift0) (define-control-macros shift0 shift0-at call-with-shift0)
(define call-with-prompt0 (define call-with-prompt0
(case-lambda (case-lambda
[(thunk) (call-with-prompt0 thunk (default-continuation-prompt-tag))] [(thunk) (call-with-prompt0 thunk (default-continuation-prompt-tag))]
[(thunk tag) [(thunk tag)
(call-with-continuation-prompt thunk tag (lambda (thunk) (thunk)))])) (call-with-continuation-prompt thunk tag (lambda (thunk) (thunk)))]))
(define-prompt-macros prompt0 prompt0-at call-with-prompt0) (define-prompt-macros prompt0 prompt0-at call-with-prompt0)
(define-prompt-macros reset0 reset0-at call-with-prompt0) (define-prompt-macros reset0 reset0-at call-with-prompt0)
;; ---------------------------------------- ;; ----------------------------------------
;; Hieb & Dybvig, PPOPP'90 ;; Hieb & Dybvig, PPOPP'90
(define (spawn f) (define (spawn f)
(let ([p (make-continuation-prompt-tag)]) (let ([p (make-continuation-prompt-tag)])
(call-with-continuation-prompt (call-with-continuation-prompt
(lambda () (lambda ()
@ -234,10 +234,10 @@
p p
(lambda (thunk) (thunk))))) (lambda (thunk) (thunk)))))
;; ---------------------------------------- ;; ----------------------------------------
;; Queinnec & Serpette, POPL'91 ;; Queinnec & Serpette, POPL'91
(define (splitter receiver) (define (splitter receiver)
(let ([p (make-continuation-prompt-tag)]) (let ([p (make-continuation-prompt-tag)])
(call-with-continuation-prompt (call-with-continuation-prompt
(lambda () (lambda ()
@ -252,17 +252,17 @@
p p
(lambda (thunk) (thunk))))) (lambda (thunk) (thunk)))))
;; ---------------------------------------- ;; ----------------------------------------
;; Gunter, Remy, & Rieke, FPLCA'95 ;; Gunter, Remy, & Rieke, FPLCA'95
;; Unfortunately, the "prompt"s in Gunter et al. are what ;; Unfortunately, the "prompt"s in Gunter et al. are what
;; we call "prompt tags". In our terminology, a "prompt" ;; we call "prompt tags". In our terminology, a "prompt"
;; is a tagged instance in a continuation. ;; is a tagged instance in a continuation.
(define (new-prompt) (make-continuation-prompt-tag)) (define (new-prompt) (make-continuation-prompt-tag))
(define-syntax set (make-rename-transformer #'prompt0-at)) (define-syntax set (make-rename-transformer #'prompt0-at))
(define-syntax cupto (make-rename-transformer #'control0-at)) (define-syntax cupto (make-rename-transformer #'control0-at))
;; ----------------------------------------
;; ----------------------------------------
)