How to iterate over a sequence in Common Lisp using a loop?

I used to use the "be elements" function for a loop to repeat a sequence of an unknown type. I just figured out that "being elements" is not provided in every implementation of Common Lisp, and I wonder if there is any clean way to iterate over a sequence using a loop. The best solution I've been able to come up with is to force the sequence into a list, and then repeat that.

+7
lisp common-lisp
source share
1 answer

No, LOOP does not provide such a function directly. If your LOOP implementation is extensible (as the standard says nothing about), you may be able to implement such a function.

LOOP has suggestions for iterating over lists - for item in list - and a suggestion for iterating over a vector - for e across vector - note that strings are also vectors, one-dimensional arrays. But not both together.

Otherwise, use MAP or MAP-INTO to loop through the sequences.

The ITERATE macro provides this function: for i in-sequence seq .

+10
source share

All Articles