Most active commenters
  • medo-bear(7)
  • CyberDildonics(4)
  • shawn_w(4)

←back to thread

333 points awkravchuk | 23 comments | | HN request time: 3.104s | source | bottom
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 #
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 #
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 #
1. CyberDildonics ◴[] No.41870528[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 #
2. zelphirkalt ◴[] No.41870582[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 #
3. taeric ◴[] No.41870627[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.
4. exe34 ◴[] No.41870793[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.
5. CyberDildonics ◴[] No.41871078[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 #
6. 0xdeadbeefbabe ◴[] No.41871087[source]
He started with a bent mind though.
7. SatvikBeri ◴[] No.41872449{3}[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 #
8. medo-bear ◴[] No.41872673[source]
Simple minds loop simply
replies(1): >>41881176 #
9. medo-bear ◴[] No.41872733{4}[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 #
10. shawn_w ◴[] No.41873366{4}[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 #
11. shawn_w ◴[] No.41873388{5}[source]
`do` is very straightforward and basic compared to the things that `loop` allows.
replies(1): >>41874508 #
12. medo-bear ◴[] No.41874508{6}[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 #
13. shawn_w ◴[] No.41874619{7}[source]
No, I mean do. It's basically just a C style for loop except with a return value. Nothing special.
replies(1): >>41874818 #
14. medo-bear ◴[] No.41874818{8}[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
replies(1): >>41876548 #
15. groovy2shoes ◴[] No.41875683{5}[source]
Not true. Scheme has `do`. See R7RS section 4.2.4 "Iteration".
replies(1): >>41876890 #
16. lispm ◴[] No.41876548{9}[source]
LOOP has the DO functionality included.

Example:

    CL-USER 18 > (do ((a 1 (+ a 1))
                      (b 10 (* b 1.5))
                      (c nil))

                     ((> a 5) (list a b (reverse c)))

                   (push (* a b) c))

    (6 75.9375 (10 30.0 67.5 135.0 253.125))

    CL-USER 19 > (loop for a = 1 then (+ a 1)
                       and b = 10 then (* b 1.5)
                       and c = NIL then c

                       when (> a 5) do (return (list a b (reverse c)))

                       do (push (* a b) c))

    (6 75.9375 (10 30.0 67.5 135.0 253.125))
replies(1): >>41876808 #
17. medo-bear ◴[] No.41876808{10}[source]
You can also express LOOP constructs in terms of DO. However if you were to construct a more exotic iterator that is not so straight forward in LOOP (beware of edge cases), I think it is more reasonable to pick DO. I think also that your example illustrates this.
replies(1): >>41876971 #
18. shawn_w ◴[] No.41876890{6}[source]
Scheme's `do` is implemented using recursion. There's a sample macro for it in 7.3.
19. lispm ◴[] No.41876971{11}[source]
I would miss the in-order collects, actually collect/maximize/... features, destructuring of lists, direct type declarations, ...

I also find DO not easy to read and understand.

The code from above I would actually write in LOOP as

    (loop for a from 1 upto 5
          and b = 10 then (* b 1.5)
          collect (* a b) into c
          finally (return (list a b c)))
I find that to be readable.
replies(1): >>41877175 #
20. medo-bear ◴[] No.41877175{12}[source]
Of course to each their own. I like LOOP a lot actually when I need to do something familiar, however for something unfamiliar DO is often my choice. It also serves as a caution to tread and think carefully when I return to the code. Sometimes, after a while, I realise how to do the DO construct succintly with LOOP
21. CyberDildonics ◴[] No.41881176[source]
I don't think this comment means anything or contains any information.
replies(1): >>41882423 #
22. medo-bear ◴[] No.41882423{3}[source]
Colorless green ideas sleep furiously
replies(1): >>41882791 #
23. CyberDildonics ◴[] No.41882791{4}[source]
This seems like you're replying with nonsense. Did you have anything coherent to say?