scheme: Use `resume' to switch coroutines.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 18 Nov 2009 11:42:17 +0000 (11:42 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 18 Nov 2009 11:42:17 +0000 (11:42 +0000)
The name `switch' was taken by Chicken as an undocumented `case'-like
control structure.  Grumble.

scheme-fringe.scm

index 53417dd..0dc93df 100644 (file)
@@ -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
      (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)))))
   ;; 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))