←back to thread

266 points awkravchuk | 3 comments | | HN request time: 0s | source
Show context
Guthur ◴[] No.41870173[source]
The event loop is brilliant example for how much `loop` is a full blown iteration DSL... love it or hate it ;)
replies(2): >>41870202 #>>41871308 #
BoingBoomTschak ◴[] No.41871308[source]
Why loop when you can https://iterate.common-lisp.dev/ instead? No s-expr-less alien syntax, no need for `do` to switch to back to Lisp syntax, normal `if`/`when` without the ugly `else`/`end` and generally useful features added.
replies(2): >>41871713 #>>41873430 #
1. shawn_w ◴[] No.41873430[source]
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.

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

replies(1): >>41873638 #
2. BoingBoomTschak ◴[] No.41873638[source]
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

  (for (i j) on list [by #'cddr])
  (for i initially init-expr then then-expr)
  (for prev previous i [initially init-expr])
  (for i in-{file,stream} [using #'reader])
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...
replies(1): >>41874197 #
3. shawn_w ◴[] No.41874197[source]
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