Next: , Previous: , Up: srfi eager-comp   [Index]


2.22.2 Abstract

This SRFI defines a modular and portable mechanism for eager comprehensions extending the algorithmic language Scheme. An eager comprehension is a convenient notation for one or more nested or parallel loops generating a sequence of values, and accumulating this sequence into a result. In its most simple form, a comprehension according to this SRFI looks like this:

(list-ec (: i 5)
  (* i i))
=> (0 1 4 9 16)

Here, i is a local variable that is sequentially bound to the values 0, 1, …, 4, and the squares of these numbers are collected in a list. The following example illustrates most conventions of this SRFI with respect to nesting and syntax:

(list-ec (: n 1 4)
         (: i n)
  (list n i))
=> ((1 0) (2 0) (2 1) (3 0) (3 1) (3 2))

In the example, the variable n is first bound to 1 then to 2 and finally to 3, and for each binding of n the variable i is bound to the values 0, 1, ..., n-1 in turn. The expression (list n i) constructs a two–element list for each bindings, and the comprehension list-ec collects all these results in a list.

The mechanism defined in this SRFI has the following properties:


Next: , Previous: , Up: srfi eager-comp   [Index]