3 ms·
There are a lot of good answers here, but I'm going to speak up as one CL expert who absolutely loathes and avoids LOOP. You can definitely write anything in C
by ScottBurson 9y ago
There are a lot of good answers here, but I'm going to speak up as one CL expert who absolutely loathes and avoids LOOP. You can definitely write anything in CL without it.
To me there are different kinds of iterations. Many are naturally written as MAPCAR/REDUCE because the iterations are all independent. Iterations where there's lots of state carried from one iteration to the next are more naturally written with DO or even using tail recursion, if the implementation you're using supports that (most do these days). The theory behind LOOP is that all iterations are fundamentally the same ("one macro to rule them all" I guess). I think this is fundamentally wrong-headed. I want to be able to see at a glance what kind of iteration it is by seeing how it is written.
- aerique 9y agoLet me be a contrary voice since I almost exclusively use LOOP (or ITER) for iteration, mainly because I really don't care what kind of iteration ought to be used[1]. I just want to iterate over elements in a data structure. If later it needs optimization I'll give it a better look. (I've rarely needed to do this.) I like my iterations to look the same so the source as a whole will be easier to grasp (for me and someone else). Then again, you're Scott Burson and I'm just an anonymous Lisper so the parent should definitely give your opinion more weight. [1] And DO has always looked ready unclear to me.
- ScottBurson 9y agoI don't use ITERATE, but that's more because I haven't felt the need than because I dislike it; it looks much better designed to me than LOOP. Maybe I should give it a try. As for giving my opinion weight, it's definitely a minority opinion among CLers, but I think we're a significant minority; I don't think I'm the only one. DO seems a little complicated at first, it's true, but once you understand it, the parts all fit together neatly. The only thing I wish had been done differently is the sense of the exit test -- currently it acts like "until" (the loop is exited when the test form evaluates to true), but the consensus of modern programming languages is that "while" behavior (exiting when the test is false) is more natural.