|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (ice-9 control) |
|
#:re-export (call-with-prompt abort-to-prompt |
|
default-prompt-tag make-prompt-tag) |
|
#:export (% abort shift reset shift* reset* |
|
call-with-escape-continuation call/ec |
|
let-escape-continuation let/ec |
|
suspendable-continuation?)) |
|
|
|
(load-extension (string-append "libguile-" (effective-version)) |
|
"scm_init_ice_9_control") |
|
|
|
(define (abort . args) |
|
(apply abort-to-prompt (default-prompt-tag) args)) |
|
|
|
(define-syntax % |
|
(syntax-rules () |
|
((_ expr) |
|
(call-with-prompt (default-prompt-tag) |
|
(lambda () expr) |
|
default-prompt-handler)) |
|
((_ expr handler) |
|
(call-with-prompt (default-prompt-tag) |
|
(lambda () expr) |
|
handler)) |
|
((_ tag expr handler) |
|
(call-with-prompt tag |
|
(lambda () expr) |
|
handler)))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (default-prompt-handler k proc) |
|
(% (default-prompt-tag) |
|
(proc k) |
|
default-prompt-handler)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax-rule (reset . body) |
|
(call-with-prompt (default-prompt-tag) |
|
(lambda () . body) |
|
(lambda (cont f) (f cont)))) |
|
|
|
(define-syntax-rule (shift var . body) |
|
(abort-to-prompt (default-prompt-tag) |
|
(lambda (cont) |
|
((lambda (var) (reset . body)) |
|
(lambda vals (reset (apply cont vals))))))) |
|
|
|
(define (reset* thunk) |
|
(reset (thunk))) |
|
|
|
(define (shift* fc) |
|
(shift c (fc c))) |
|
|
|
(define (call-with-escape-continuation proc) |
|
"Call PROC with an escape continuation." |
|
(let ((tag (list 'call/ec))) |
|
(call-with-prompt tag |
|
(lambda () |
|
(proc (lambda args |
|
(apply abort-to-prompt tag args)))) |
|
(lambda (_ . args) |
|
(apply values args))))) |
|
|
|
(define call/ec call-with-escape-continuation) |
|
|
|
(define-syntax-rule (let-escape-continuation k body ...) |
|
"Bind K to an escape continuation within the lexical extent of BODY." |
|
(let ((tag (list 'let/ec))) |
|
(call-with-prompt tag |
|
(lambda () |
|
(let ((k (lambda args |
|
(apply abort-to-prompt tag args)))) |
|
body ...)) |
|
(lambda (_ . results) |
|
(apply values results))))) |
|
|
|
(define-syntax-rule (let/ec k body ...) |
|
(let-escape-continuation k body ...)) |
|
|