Comment by shawn_w
12 hours ago
If I used Common Lisp more I'd probably have a go at copying Racket's `for` forms[1]; they're really nice because you can usally tell at a glance what they're going to return - `for/list` returns a list for example. No having to scan the body for a `collect`.
But in the meantime since discovering iterate I've barely used `loop`. It just feels so much more lispy and I find myself running to the documentation less often.
Interesting concept, but it visually has the same problem as loop IMO, using keywords to implement a new syntax instead of seamlessly blending with Lisp (at the cost of needing code walking, though).
And it seems to lack all the iterations drivers (incl. builtin destructuring) that make half of loop/iterate's usefulness and "reads like English" comfy factor; especially liking
The two lasts are iterate goodies and I often use the last with these custom readers: https://git.sr.ht/~q3cpma/cl-utils/tree/master/item/src/read...
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 ¯\_(ツ)_/¯.