generators with success and failure, maybe and make-coroutine Amirouche Boubekki 09 May 2021 09:03 UTC

Follow-up on the conversation at
https://srfi-email.schemers.org/srfi-221/msg/16341839/

Marc, you suggest several ideas. One is a more general generator
protocol that could support multiple values and failures that are not
only eof-object.

Are generators with success and failure related to make-coroutine?

It seems make-coroutine protocol uses explicit yield and next procedures.

On a somewhat related note, I benchmarked make-coroutine-generator on
several scheme:

chez         : ▏ 159.00
gambit       : ▇ 585.00
racket       : ▇ 663.00
ruse/chez    : ▇ 700.00
chicken      : ▇▇ 833.00
cyclone      : ▇▇ 1107.00
gambit/nodejs: ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 7346.00
guile        : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 13720.00
ruse/nodejs  : ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 20000.00

And I also compared guile's call/ec with chez's call/cc. chez is three
times faster than guile. My takeaway is that in general call/cc and
prolly call/ec are too slow to be called in a hot path.

One missing piece in the puzzle is to compare make-coroutine-generator
based generators with the equivalent code that does not rely on
make-coroutine-generator.

if make-coroutine can be implemented in terms of call/ec, it will be
easier to implement SRFI-180 (JSON) and will lead to more readable
code. I agree that call/cc or call/ec should be favored because the
code is more readable, but SRFI-158 generators are performance
oriented, and experience proves relying on make-coroutine-generator
can not compete, so far.

Regarding Maybe, it seems to me it is new to Scheme, and so far R7RS
was built around success and failure procedures.

When I understand better the alternative approaches (SRFI-158,
SRFI-158 with make-coroutine-generator, generator with maybes,
generator with success and failure, and make-coroutine) I will adapt
SRFI-180 code to compare performance.

Best regards,

Amirouche