Generators and accumulators John Cowan (18 Jan 2020 21:46 UTC)
Re: Generators and accumulators Amirouche Boubekki (21 Jan 2020 10:35 UTC)
Re: Generators and accumulators Lassi Kortela (21 Jan 2020 22:45 UTC)
Re: Generators and accumulators John Cowan (21 Jan 2020 22:48 UTC)
Re: Generators and accumulators Lassi Kortela (21 Jan 2020 22:57 UTC)
Re: Generators and accumulators John Cowan (21 Jan 2020 23:02 UTC)
Re: Generators and accumulators Lassi Kortela (21 Jan 2020 23:15 UTC)

Re: Generators and accumulators Lassi Kortela 21 Jan 2020 22:57 UTC

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