Most active commenters
  • shawn_w(5)
  • medo-bear(4)
  • BoingBoomTschak(3)

←back to thread

266 points awkravchuk | 25 comments | | HN request time: 0.001s | source | bottom
1. 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 #
2. awkravchuk ◴[] No.41870202[source]
I used to scoff at it at first, but after a few years of CL programming loop is one of my favourite CL constructs :)
replies(1): >>41870359 #
3. taeric ◴[] No.41870359[source]
I'm with you there. Is a bit of a mind bend, as I really disliked it the first few times I saw it.

For an even sillier mind bend, I'm using tagbody to be able to directly transcribe some of Knuth's algorithms as I am learning them.

replies(2): >>41870528 #>>41870541 #
4. CyberDildonics ◴[] No.41870528{3}[source]
I don't understand why turning a simple loop into a 'mindbend' is considered good. The downfall of programming is complexity, if you're getting your mind blown by a loop how are you going to do the rest of the program?
replies(4): >>41870582 #>>41870627 #>>41871087 #>>41872673 #
5. awkravchuk ◴[] No.41870541{3}[source]
Cool! Using tagbody feels like writing supercharged C or even assembler to me (not that I've used it much, but still).
6. zelphirkalt ◴[] No.41870582{4}[source]
Something can be mindbending in its implementation, but offer a very convenient interface at the same time.

If mindbending isn't relating to its usage, but to its implementation, then I could see, how it could still be a good thing.

replies(2): >>41870793 #>>41871078 #
7. taeric ◴[] No.41870627{4}[source]
The mindbend was more of my approach to the construct. It began with disdain before even really using it much. Looking back, I really couldn't articulate what I disliked about it.
8. exe34 ◴[] No.41870793{5}[source]
mindbending can also refer to something being deceptively simple. you might think it would be a big complicated mess, but using this one weird trick makes it really obvious what's going on.
9. CyberDildonics ◴[] No.41871078{5}[source]
How does that relate to a simple loop construct though? Why would you want that to be mind bending in interface or implementation? Every other language makes it as simple as possible.
replies(1): >>41872449 #
10. 0xdeadbeefbabe ◴[] No.41871087{4}[source]
He started with a bent mind though.
11. 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 #
12. Jtsummers ◴[] No.41871713[source]
Have they fixed the problem in Iterate yet where it breaks any uses of the built-in count function?
replies(1): >>41872696 #
13. SatvikBeri ◴[] No.41872449{6}[source]
This isn't really true – you have languages like Odin that only have a for loop, no while loop, that only supports index-based iteration. Then you have languages like Python that let you loop over an arbitrary iterable, and define your own iterables. Some languages allow conditionals in loops, some don't. Some let you loop over multiple iterables, while some only take one at a time.

Common Lisp happens to be on the upper end of what loop allows – you can use it as a standard for loop pretty easily, but the interface gives you many other options.

replies(2): >>41872733 #>>41873366 #
14. medo-bear ◴[] No.41872673{4}[source]
Simple minds loop simply
15. BoingBoomTschak ◴[] No.41872696{3}[source]
Sadly no. Biggest bug in there, "fortunately". Easy to patch, though.
16. medo-bear ◴[] No.41872733{7}[source]
> Common Lisp happens to be on the upper end of what loop allows – you can use it as a standard for loop pretty easily, but the interface gives you many other options.

If you really wanna get freaky try 'do. It is the heroin addicted cousin of 'loop

https://www.lispworks.com/documentation/HyperSpec/Body/m_do_...

replies(1): >>41873388 #
17. shawn_w ◴[] No.41873366{7}[source]
And then there's Scheme, where there are no iterative loops; all looping is done with recursion. You can build pretty much everything other languages do with loops on top of that, though.
replies(1): >>41875683 #
18. shawn_w ◴[] No.41873388{8}[source]
`do` is very straightforward and basic compared to the things that `loop` allows.
replies(1): >>41874508 #
19. 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 #
20. BoingBoomTschak ◴[] No.41873638{3}[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 #
21. shawn_w ◴[] No.41874197{4}[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

22. medo-bear ◴[] No.41874508{9}[source]
oh no. maybe you have in mind 'dolist or 'dotimes

'do is much more general and way more powerful. in some sense 'loop is the taming of 'do. see for example

https://www.lispworks.com/documentation/lcl50/loop/loop-7.ht...

replies(1): >>41874619 #
23. shawn_w ◴[] No.41874619{10}[source]
No, I mean do. It's basically just a C style for loop except with a return value. Nothing special.
replies(1): >>41874818 #
24. medo-bear ◴[] No.41874818{11}[source]
yes the syntax for 'do is simple, like that of lisp. however 'do allows you to make far more complex iteration constructs than 'loop. 'loop is just a DSL to make some of these constructs more concise. read up on it
25. groovy2shoes ◴[] No.41875683{8}[source]
Not true. Scheme has `do`. See R7RS section 4.2.4 "Iteration".