Consider the following snippet of C code; the actual values for M
and the content of arr don't actually matter.
int arr[M] = {...};
for (int i=0; i<M; ++i) {
for (int j=i+1; j<M; ++j) {
/* do something */
}
}
What would be the (idiomatic and efficient) Common Lisp analog using the loop macro (or if loop is not right tool, any other construct)?
I know that comparing array access and list access is not correct but could not come up with a better example.
One possibility I tried is the following:
(defvar l '(1 2 ...))
(loop :for n :on l :do
(loop :for x :in (cdr n) :do
;; do something
))
But this seems rather clunky.
Please note, that other similar questions deal with ranges not with lists.