Building robust generators with yield, continue, and set! Amirouche Boubekki (21 Feb 2021 10:20 UTC)
Re: Building robust generators with yield, continue, and set! Marc Nieper-Wißkirchen (21 Feb 2021 10:52 UTC)

Building robust generators with yield, continue, and set! Amirouche Boubekki 21 Feb 2021 10:19 UTC

I use the following pattern often:

(define (my-generator-operation generator)
   (define yield #f)

   (define (fini!) (set! yield eof-object) (eof-object))

   (define (continue)
       (if (end?)
           (fini!)
           (do-something))

  (set! yield continue)

  (lambda ()
    (yield))