summaryrefslogtreecommitdiff
path: root/2d/coroutine.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-02-06 21:18:32 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-02-06 21:18:32 -0500
commit3267fc1ace530a37fecd05d0838809c6f0af22a7 (patch)
tree0b3bca668da67ad3acb6a87b12a139e870909734 /2d/coroutine.scm
parent21ff408c45685afacd3c0fffb3f81c46e9b00874 (diff)
Add new coroutine macro.
* 2d/coroutine.scm (call-with-coroutine): New name for coroutine. (coroutine): New macro. (colambda, codefine, codefine*): Use call-with-coroutine. * examples/coroutine.scm: Use coroutine macro. * README.org: Update coroutine and agenda examples.
Diffstat (limited to '2d/coroutine.scm')
-rw-r--r--2d/coroutine.scm18
1 files changed, 12 insertions, 6 deletions
diff --git a/2d/coroutine.scm b/2d/coroutine.scm
index 036cdc4..322f236 100644
--- a/2d/coroutine.scm
+++ b/2d/coroutine.scm
@@ -22,14 +22,15 @@
;;; Code:
(define-module (2d coroutine)
- #:export (coroutine
+ #:export (call-with-coroutine
+ coroutine
colambda
codefine
codefine*)
#:replace (yield))
-(define (coroutine thunk)
- "Calls a procedure that can yield a continuation."
+(define (call-with-coroutine thunk)
+ "Apply THUNK with a coroutine prompt."
(define (handler cont callback . args)
(define (resume . args)
;; Call continuation that resumes the procedure.
@@ -42,11 +43,16 @@
;; Call procedure.
(call-with-prompt 'coroutine-prompt thunk handler))
+;; emacs: (put 'coroutine 'scheme-indent-function 0)
+(define-syntax-rule (coroutine body ...)
+ "Evaluate BODY as a coroutine."
+ (call-with-coroutine (lambda () body ...)))
+
;; emacs: (put 'colambda 'scheme-indent-function 1)
(define-syntax-rule (colambda args body ...)
"Syntacic sugar for a lambda that is run as a coroutine."
(lambda args
- (coroutine
+ (call-with-coroutine
(lambda () body ...))))
;; emacs: (put 'codefine 'scheme-indent-function 1)
@@ -57,7 +63,7 @@ coroutine."
;; Create an inner procedure with the same signature so that a
;; recursive procedure call does not create a new prompt.
(define (name ...) . body)
- (coroutine
+ (call-with-coroutine
(lambda () (name ...)))))
;; emacs: (put 'codefine* 'scheme-indent-function 1)
@@ -68,7 +74,7 @@ coroutine."
;; Create an inner procedure with the same signature so that a
;; recursive procedure call does not create a new prompt.
(define* (name . formals) . body)
- (coroutine
+ (call-with-coroutine
(lambda () (apply name args)))))
(define (yield callback)