From cf500c87df4c2cbf75bef281b3eed5e9d4757352 Mon Sep 17 00:00:00 2001 From: Amirouche Date: Sat, 21 Nov 2020 10:13:58 +0100 Subject: [PATCH 1/2] srfi-158: generators: remove comment because it pass the tests. --- %3a158/srfi-158-impl.scm | 1 - 1 file changed, 1 deletion(-) diff --git a/%3a158/srfi-158-impl.scm b/%3a158/srfi-158-impl.scm index a66a180..83294bc 100755 --- a/%3a158/srfi-158-impl.scm +++ b/%3a158/srfi-158-impl.scm @@ -167,7 +167,6 @@ ;; make-for-each-generator - ;FIXME: seems to fail test (define (make-for-each-generator for-each obj) (make-coroutine-generator (lambda (yield) (for-each yield obj)))) From 9fe1e2f3a8328d3c670f54301bea0046def8de45 Mon Sep 17 00:00:00 2001 From: Amirouche Date: Sat, 21 Nov 2020 10:19:43 +0100 Subject: [PATCH 2/2] srfi-158: generators: gtake: avoid make-coroutine-generator --- %3a158/srfi-158-impl.scm | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/%3a158/srfi-158-impl.scm b/%3a158/srfi-158-impl.scm index 83294bc..ab812dc 100755 --- a/%3a158/srfi-158-impl.scm +++ b/%3a158/srfi-158-impl.scm @@ -326,18 +326,17 @@ ;; gtake (define gtake - (case-lambda ((gen k) (gtake gen k (eof-object))) - ((gen k padding) - (make-coroutine-generator (lambda (yield) - (if (> k 0) - (let loop ((i 0) (v (gen))) - (begin (if (eof-object? v) (yield padding) (yield v)) - (if (< (+ 1 i) k) - (loop (+ 1 i) (gen)) - (eof-object)))) - (eof-object))))))) - - + (case-lambda + ((gen k) (gtake gen k (eof-object))) + ((gen k padding) + (define (%gtake gen k) + (lambda () + (if (zero? k) + (eof-object) + (begin + (set! k (- k 1)) + (gen))))) + (%gtake (gappend gen (lambda () padding)) k)))) ;; gdrop (define (gdrop gen k)