On Sun, Aug 2, 2020 at 4:10 AM Amirouche Boubekki <xxxxxx@gmail.com> wrote:

Outside the performance differences between SRFI-41 and SRFI-158,
there is also a semantic difference, both offering different
"guarantees".

You should perhaps also look at SRFI 127 (Lazy Sequences), which is about improper lists with a generator in the tail.  There are operations to process the list in such a way that the generator will be invoked on reaching the end of the list.  All the pairs in the list should be treated as immutable except the last one, which is mutated whenever the generator is called in order to insert a new pair.  When the generator runs out, it is replaced by ().

Otherwise said, SRFI-41 supports backtracking, whereas plain generators do not.

So SRFI 127 provides backtracking, but already generated values are "thunked" in the Haskell sense: it is not necessary to call a procedure to get those values, just car.  I would expect them to provide comparable performance to generators.  Unlike SRFI 41 streams, SRFI 127 sequences are odd; the first element is always generated eagerly, making them functionally more like SRFI 40 streams.

While I am at it, when implementing generators, you should properly
take care of end-of-file, I think once eof was produced, the generator
should always produce eof...

There may be bugs in the SRFI 158 library, but in general that is part of the definition.  (There are cases that bend this: read-char is a generator even though after you get an EOF from the terminal on Posix, you can still read characters after that.)



John Cowan          http://vrici.lojban.org/~cowan        xxxxxx@ccil.org
Pour moi, les villes du Silmarillion ont plus de realite que Babylone.
                --Christopher Tolkien, as interviewed by Le Monde