chickadee » foof-loop » LISTING

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

Usage:

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

These each produce lists of the accumulated data with a final cdr of <tail>. LISTING yields a list in the order that the data were produced; LISTING-REVERSE yields a list in the reverse order of that.

<Tail>, if supplied, is evaluated once before the beginning of the loop. The default value of <tail> is the empty list.

For LISTING, <result> is a final variable.

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

   (define (list-tabulate length procedure)
     (loop ((for i (up-from 0 (to length)))
            (for list (listing (procedure i))))
       => list))
   
   (define (take list count)
     (loop ((for i (up-from 0 (to count)))
            (for elt (in-list list))
            (for prefix (listing elt)))
       => prefix))
   
   (define (append-reverse list tail)
     (loop ((for elt (in-list list))
            (for result (listing-reverse (initial tail) list)))
       => result))
   
   (define (unzip5 list)
     (loop ((for component (in-list list))
            (for result1 (listing (first component)))
            (for result2 (listing (second component)))
            (for result3 (listing (third component)))
            (for result4 (listing (fourth component)))
            (for result5 (listing (fifth component))))
       => (values result1 result2 result3 result4 result5)))