Next: , Previous: Common List Operations, Up: Top


56 LOL Iteration

A lol is a list of lists, with all the sub-lists having the same number of elements. It is a common structure for smallish inline data sets. The expression:

(use-modules (ice-9 lol))

makes available some convenient syntax sugaring of apply, map and for-each. In these macros, formals should be a list of symbols naming the variables to be bound to each sub-list element for the forms in body.

— Scheme Macro: lol-map formals lol [body...]

Apply the procedure (lambda formals body) to the sub-lists of lol and return the results as a list.

— Scheme Macro: lol-for-each formals lol [body...]

Apply the procedure (lambda formals body) to the sub-lists of lol.

The following example shows two idempotent fragments (they both display monday and wednesday), written “manually” and with lol-for-each.

     (define TABLE '((#t monday)
                     (#f tuesday)
                     (#t wednesday)))
     
     (for-each (lambda (sub)
                 (apply (lambda (sleep? day)
                          (and sleep? (write-line day)))
                        sub))
               TABLE)
     
     (lol-for-each (sleep? day) TABLE
       (and sleep? (write-line day)))