chickadee » list-comprehensions » collect

(collect item qualifier ....)syntax

where item is an expression with variables to be bound in the qualifiers. Each qualifier is of the form (var lst fltr ...) whith

  • var a variable
  • lst a list from which values are chosen
  • fltr a filter expression

Creates a new list by binding var to each element of lst in sequence, and if it passes the checks fltr ..., inserts the item expression into the result list. The qualifieres are processed sequentially from left to right, so that filters of a qualifier have access to the variables of qualifiers to its left.

For example

  (collect (list x y z)
       (x (list #\A #\B))
       (y (list 1 2))
       (z (list #f #t)))

produces

  ((#\A 1 #f)
   (#\A 1 #t)
   (#\A 2 #f)
   (#\A 2 #t)
   (#\B 1 #f)
   (#\B 1 #t)
   (#\B 2 #f)
   (#\B 2 #t))