Comment by shawn_w

12 hours ago

Racket splits up the iteration forms from what to iterate over (sequences[1]). You can compose different sequence constructors together, or make brand new ones, without introducing new syntax.

It has limited destructuring - sequences can return multiple values, all of which can be bound. There's an adapter to convert one that does that into returning a single list, but not the other way around. If there was it could be used with `in-slice` to be equivalent to your first example.

I could probably write a new sequence to get the `previous` behavior; don't think `initially ... then` is possible.

Lots of sequences for reading from open ports (the Racket/Scheme name for CL streams)... `(for ([i (in-port)]) ...)` for example (with an optional reader argument defaulting to `read`).

[1]: https://docs.racket-lang.org/reference/sequences.html

Ah, I see, though I'd say it pollutes the function namespace a bit this way (as "in-x" semantically only makes sense in a loop) and missing on-list. Technically, you could do most of these in a few lines of CL too, but well, convenience is the point of these macros.

Those seem to return sequences instead of streams/iterators, any idea why? Though it says "An in-list application can provide better performance for list iteration when it appears directly in a for clause", so I guess there's some macro magic at play.

Anyway, thanks for exposing those, Racket does seem to be pretty practical (and with its Chez backend, I guess it's pretty fast); can't stand the square brackets used as syntax (as opposed to vector literals used as data), though ¯\_(ツ)_/¯.