chickadee » foof-loop » APPENDING

(APPENDING [(INITIAL <tail>)] ...)syntax
(APPENDING-REVERSE [(INITIAL <tail>)] ...)syntax

Usage:

   (FOR <result> (APPENDING [(INITIAL <tail>)] ...))
   (FOR <result> (APPENDING-REVERSE [(INITIAL <tail>)] ...))

These append the accumulated data into a list with a final cdr of <tail>. APPENDING maintains the order of the lists and their elements; APPENDING-REVERSE reverses the elements of the lists. The accumulated data must all be proper lists.

<Tail>, if supplied, is evaluated once in the environment outside the loop. The default value of <tail> is the empty list.

For APPENDING, <result> is a final variable.

For APPENDING-REVERSE, <result> is a loop variable; its value in the final expression is the reverse-concatenated list.

   (define (concatenate lists)
     (loop ((for list (in-list lists))
            (for result (appending list)))
       => list))