Computing Reviews

Programming with generators: an introduction
Berztiss A., Ellis Horwood,Upper Saddle River, NJ,1990.Type:Book
Date Reviewed: 11/01/92

In this well-written introduction to the field of generators, the author defines a generator and elucidates using numerous examples. He compares generators with functions, highlighting their advantages. He then applies generators to several well-known problems. Next, he shows how to use generators for backtracking problems using the generate and test paradigm. Finally, he discusses several alternatives for the implementation of generators.

In the first chapter, Berztiss compares functions and generators. A generator is similar to a function except that when a function is called it always starts execution at the top. A generator, on the other hand, can resume execution at the spot from which it last returned.

One example from the first chapter is a preorder tree traversal generator. Each call to the generator returns the next node for the preorder traversal. This type of generator is much more convenient than the alternative of mixing the code for traversal with the operations to be performed on each node.

The book discusses the following basic applications of generators: heapsort, Towers of Hanoi, in-order tree traversal, text formatting, sorting and merging, spell checking, and matrix multiplication.

In the third chapter, the author discusses backtracking using the generate and test paradigm. The idea is to generate potential solutions for some problem and then to test these possible solutions. A generator is useful to help separate the concept of generation and testing. Examples of backtracking algorithms discussed are the n queens problem, shortest path determination in a graph, and the A* algorithm for informed search.

The fourth and final chapter is a discussion of implementation issues. The first suggestion for implementation is to use an existing language, such as Pascal, that has functions. In this environment, the programmer must branch to the proper place in the function for each call. This requirement becomes a problem when implementing recursive generators like preorder tree traversals. The author discusses how to implement generators using the Icon and Lucid programming languages. Each of these languages contains unique features that can be used for implementing generators. The chapter concludes with a discussion of using pipes to connect independent processes and a discussion of dataflow computations. Both of these techniques are suitable for implementing generators.

The purpose of the book is to introduce the subject of generators. Overall, the author presents generators clearly. The examples used are commonly studied in various computer science courses and are fairly simple to understand. Several of the examples clearly illustrate that the generator paradigm is appropriate. While generators are rarely included in programming languages, the author emphasizes the utility of developing software with the generator paradigm using other languages.

This book is useful for students, practitioners, and language designers. While it is too limited in scope to serve as the only text for a course, it could serve as supplementary material for a variety of courses. Software engineers will find the concept of generators useful for many problems. Language designers should be aware of generators and should consider their inclusion in new and revised languages.

Reviewer:  B. R. Seyfarth Review #: CR114842

Reproduction in whole or in part without permission is prohibited.   Copyright 2024 ComputingReviews.com™
Terms of Use
| Privacy Policy