Hacker News new | comments | show | ask | jobs | submit login

That might be true. It is indeed complex if you look at the BNF in the hyper-spec. (http://www.lispworks.com/documentation/HyperSpec/Body/m_loop...)

If you ignore the hyperspec, however, and get a feel for it by looking at examples and writing code using it, it becomes quite simple. It is very useful when you are translating C or Java code.

(http://www.unixuser.org/~euske/doc/cl/loop.html)

I find it quite readable in comparison to many of common lisp alternatives for iteration. And I kind of disagree that simple things aren't simple.

For example: (loop for i from 0 below 10 do ...)

Is pretty much the simplest construct that you normally need. Granted, I would likely just use dotimes in that case... but lets say you are iterating between 5 and 15, dotimes becomes unwieldy, where the for loop is pretty much the same code with the numbers changed.

(loop for i from 5 below 15 do ....)

Now try incrementing by 2

(loop for i from 5 below 15 by 2 do ....)

compare to the similar do* code

(do* ((i 5 (+ i 2)))

    ((>= i 15))

  ....)
kind of a toss up to me.

Not that I don't understand your point... in fact, as little as a year ago, I felt that way too... but I have since changed my mind.

My current preference is to use do* if writing a macro that needs iteration, and to use loop when I am doing something similar to a list comprehension or array traversal.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: