Am Do., 28. Okt. 2021 um 02:31 Uhr schrieb John Cowan <xxxxxx@ccil.org>:


On Mon, Oct 25, 2021 at 6:38 AM Marc Nieper-Wißkirchen <xxxxxx@gmail.com> wrote:

You need to create something because of persistence. An SSC can reuse the created closure if the old iterator state is immediately thrown away.

Generators are for situations where you don't care about persistence.

Sure. The problematic areas are when you think you don't have to care about persistence but actually, you have to do.
 
That's the wrong question and cause all my alarm bells to ring, so to speak. While Scheme is somewhat a multi-paradigm language, its focus has always been on functional, not imperative code.

Functional yes, pure functional no.  All of Scheme's original data structures are mutable, as are its variables.

That's unrelated to what I was talking about. While Scheme is not a pure language like Haskell and offers `set!', it does not encourage a programming style that uses mutation a lot outside areas where monads would be ued in Haskell.
 
Otherwise, we better program in C all day, which is, if done right, probably faster than any other solution.)

"Done right" in a C context means "fast and unsafe".  There are plenty of imperative languages that are safe, and safe C implementations do exist (Vacietis) but aren't fast.

I wasn't talking about C being imperative or not; I was talking about trading efficiency for the sake of safety and clear code is usually a good thing unless one really needs utmost performance.
 

In Scheme, we write

(vector-map (lambda (x) (+ x 1) vec)

and not

(let* ([n (vector-length vec)]
       [res (make-vector n)])
  (do ([i 0 (fx+ i 1)])
      ((fx=? i n) res)
    (vector-set! res i (+ (vector-ref vec i) 1))))

even if a non sufficiently smart compiler will create a closure for the procedure argument to `vector-map'. (There are certainly better examples, but you get the idea.)

An SSC will compile them in exactly the same way, just as modern C compilers will compile the statements "x++;", "++x;", "x += 1;", and "x = x + 1;" in exactly the same way.

Exactly.