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

#### Arrays in the sense of SRFI-25

In order to create an array from a sequence of elements, a comprehension with the following syntax would be useful:

```(array-ec shape qualifier* expression)
```

The comprehension constructs a new array of the given shape by filling it row–major with the sequence of elements as specified by the qualifiers. On the generator side, it would be most useful to have a generator of the form:

```(:array vars arg)
```

running through the elements of the array in row–major. For the optional index variable, the extension `(index k1 k*)` could be defined where k1 `k*` are variable names indexing the various dimensions.

#### Random Numbers in the sense of SRFI-27

In order to create a vector or list of random numbers, it would be convenient to have generators of the following form:

```(:random-integer [ range [ number ] ] )
(:random-real    [ number ] )
```

where range (default 2) indicates the range of the integers and number (default infinity) specifies how many elements are to be generated. Derived from these basic generators, one could define several other generators for other distributions (e.g. Gaussian).

#### Bitstrings in the sense of SRFI-33

As eager comprehensions are efficient, they can be useful for operations involving strings of bits. It could be useful to have the following comprehension:

```(bitwise-ec qualifier* expression)
```

which constructs an integer from bits obtained as values of expression in the ordering defined by SRFI-33. In other words, if the sequence of values is `x[0]`, `x[1]`, …, `x[n-1]` then the result is:

```x[0] + x[1] 2 + ... + x[n-1] 2^(n-1)
```

On the generator side, a generator of the form:

```(:bitwise vars arg1 arg*)
```

runs through the sequence of bits obtained by appending the binary digits of the integers arg1 arg*.

#### Streams in the sense of SRFI-41

It is possible to “lazify” the eager comprehension `list-ec`, constructing a stream in the sense of SRFI-41. Clearly, such a comprehension (`stream-ec`) is not eager at all since it only runs the loops when results are requested. It is also possible to define a `:stream` generator with the same API as `:list` but running through streams instead of lists.

For what is worth, the file srfi40-ec.scm implements `:stream` and `stream-ec` and gives an example. The implementation makes substantial use of `call-with-current-continuation` to run the loop only when necessary. In some implementations of Scheme this may involve considerable overhead.

Eager comprehensions can also be used to process files. However, bear in mind that an eager comprehension wants to read and process the entire file right away. Nevertheless, these generators would be useful for reading through the lines of a file or through the characters of a file:

```(:lines-of-file vars file)
(:chars-of-file vars [ (line variable1) ] [ (column variable2) ] file)
```

Here file is either an input port or a string interpreted as a filename. In a similar fashion, generators reading from sockets defined by URLs or other communication facilities could be defined.

#### The Scheme shell Scsh

In the Scheme–shell, Scsh, it could be useful to have certain comprehensions and generators. Candidates for comprehensions are `begin-ec`, `|-ec`, `||-ec`, and `&&-ec`.

Concerning generators, it might be useful to have `:directory` running through the records of a directory, and maybe a sophisticated `:file-match-generator` could enumerate file record in a directory structure. Optional variables of the generators could give convenient access frequent components of the file records (e.g. the filename). Another candidate is `:env` to run through the environment associations. It is left to other authors and other SRFIs to define a useful set of comprehensions and generators for Scsh.

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