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))