From 652d4a587e0ab95a9673ca1c8fd6f109a0df6a25 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 18 Nov 2009 11:42:17 +0000 Subject: [PATCH] scheme: Use `resume' to switch coroutines. The name `switch' was taken by Chicken as an undocumented `case'-like control structure. Grumble. --- scheme-fringe.scm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scheme-fringe.scm b/scheme-fringe.scm index 53417dd..0dc93df 100644 --- a/scheme-fringe.scm +++ b/scheme-fringe.scm @@ -52,7 +52,7 @@ ;; this is #f. %calling-coroutine) -(define (switch-cr coroutine . args) +(define (resume coroutine . args) ;; Switch to COROUTINE, passing it ARGS. When this coroutine is resumed ;; (by calling `switch', naturally) it will return the values passed as ;; arguments. A new coroutine (made by `make-coroutine') receives these @@ -77,20 +77,20 @@ (define (name . args) (make-coroutine (lambda () (begin . body) - (switch-cr (calling-coroutine) #f #f))))))) + (resume (calling-coroutine) #f #f))))))) (define (yield object) ;; Yield OBJECT from a generator. The generator protocol returns two ;; values each time: either an object and #t, or #f twice to mark the end ;; of the sequence. - (with-values () (switch-cr (calling-coroutine) object #t) #f)) + (with-values () (resume (calling-coroutine) object #t) #f)) (define (list-generator gen) ;; Collect the elements generated by GEN into a list and return it. (let loop ((l '())) - (with-values (it any?) (switch-cr gen) + (with-values (it any?) (resume gen) (if any? (loop (cons it l)) (reverse l))))) @@ -100,8 +100,8 @@ ;; order. (let loop () - (with-values (a any-a?) (switch-cr gen-a) - (with-values (b any-b?) (switch-cr gen-b) + (with-values (a any-a?) (resume gen-a) + (with-values (b any-b?) (resume gen-b) (cond ((not any-a?) (not any-b?)) ((not any-b?) #f) ((eqv? a b) (loop)) -- 2.11.0