4 ms·
I agree with you to some degree. Higher order functions should be used wherever possible and there should be some alternatives to LOOP for the common cases such
by malisper 12y ago
I agree with you to some degree. Higher order functions should be used wherever possible and there should be some alternatives to LOOP for the common cases such as iterating over a range of numbers. It is much easier to understand patterns when they are built into the language than when they are written out using LOOP.
The thing is LOOP is very good at creating ad hoc kinds of loops. Say you are writing a loop to do password validation. Repeat at most N times and then lock the account or go through once a correct password is entered. That kind of iteration is too specific for pretty much any kind of looping construct besides LOOP.
As I see it, LOOP is not about creating "one macro to rule them all", it's about creating a macro that's a catch-all. One that you can always use when nothing else quite describes what you want.
I'm just thinking out loud.
- ScottBurson 12y agoI would probably use DO for the password validation example. It's strange to me that people think of DO as complicated; there is a little complexity there, to be sure, but much less than for LOOP. Once you understand that the inits and updates are done in parallel, and you get where the exit test goes, you've got it; there are no more rules to learn. I understand that LOOP seems simple in simple cases, but that simplicity is evidently deceptive, as attested by the comments I was replying to.
- malisper 12y agoMakes sense. It's just to me, as someone who knows LOOP that (loop repeat n thereis (valid (read-password)) finally (lock-account)) seems simpler than (do ((i 0 (+ i 1))) ((>= i n) (lock-account)) (when (valid (read-password)) (return t))) You are definitely right that loop is deceptively complex. In the code I gave, a reader would need to know that thereis skips the epilogue when terminating the loop (I would comment the code if it was going to be seen by others). I'm now finding it incredible how much lingo I used in the last sentence.