Common Lisp the Language, 2nd Edition


next up previous contents index
Next: Generators Up: Generators and Gatherers Previous: Generators and Gatherers

B.1. Introduction

change_begin
Generators are generalized input streams in the sense of Smalltalk [20]. A generator can produce a potentially unbounded number of elements of any type. Individual elements are not computed until requested by next-in. When an element is taken from a generator, it is removed by side effect. Subsequent uses of next-in obtain later elements.

There is a close relationship between a generator and a series of the elements it produces. In particular, any series can be converted into a generator. As a result, all the scanner functions used for creating series (see appendix A) can be used to create generators as well. There is no need to have a separate set of functions for creating generators.

Gatherers are generalized output streams. Elements of any type can be entered into a gatherer using next-out. The gatherer combines the elements together in time-sequence order into a net result. This result can be retrieved using result-of.

There is a close relationship between a gatherer and a collector function that combines elements in the same way. In particular, any one-input one-output collector can be converted into a gatherer. As a result, all the collectors used for computing summary results from series can be used to create gatherers. There is no need to have a separate set of functions for creating gatherers.
change_end



next up previous contents index
Next: Generators Up: Generators and Gatherers Previous: Generators and Gatherers


AI.Repository@cs.cmu.edu