There’s a nice explanation of these Lisp macros in the book Loving Lisp, or the Savvy Programmer’s Secret Weapon. by Mark Watson.
What makes them easy to understand and remember their syntax is the choice of variable names.
(dolist (a-variable a-list [optional-result-value]) ...body... )
(dotimes (an-index-variable max-index-plus-one [optional-result-value]) ...body... )
(do ((variable-1 variable-1-init-value variable-1-update-expression) (variable-2 variable-2-init-value variable-2-update-expression) ... (variable-N variable-N-init-value variable-N-update-expression)) (loop-termination-test loop-return-value) optional-variable-declarations expressions-to-be-executed-inside-the-loop)
Many authors would put
x instead of
an-index-variable, and then would add an explanation after the code:
xis an index variable …
As a result, the reader has to constantly jump between the explanation and the code, and the syntax becomes difficult to learn and remember.
Maybe this is the reason why many Lisp programmers are not comfortable with
do and prefer using
loop instead. A code with
do quickly becomes incomprehensible if the names of your variables are not self-explanatory.