The point is that if you have a generator or accumulator created externally to JSON, you can use it.  Textual input ports work on files, strings, and maybe sockets, but they don't work on other sources of data.  Generators can be wrapped around *any* source of data, at the expense of being unable to inline it unless you have a whole-program compiler.  If you are able to use an explicit lambda that gets inlined, so much the better, but I think the normal use case will be something quite different.

On Tue, Jan 21, 2020 at 5:57 PM Lassi Kortela <xxxxxx@lassi.io> wrote:
>>     Are character-by-character generators and accumulators reasonably fast?
>>     Are they amenable to well-known compiler optimizations?

> Gens and accs are just procedures of zero arguments and one argument
> respectively, so their efficiency is constrained by what they do.  Doing
> JSON pretty much requires char-by-char parsing.

This inlines nicely in Chez and Loko, gets rid of the generator lambda:

(expand/optimize
    '(let* ((chars (string->list "hello world"))
            (gen (lambda ()
                   (if (null? chars) (eof-object)
                       (let ((char (car chars)))
                         (set! chars (cdr chars))
                         char)))))
       (let loop ()
         (let ((char (gen)))
           (if (eof-object? char) (newline)
               (begin (display char) (loop)))))))