4.2. Generating a Primer (with apologies to Dick and Jane)
For those who attended elementary school in the United States a generation or two ago, sentences like this are almost certainly familiar. For many years, firstgraders were taught to read using primer texts designed to develop reading skills through the repetition of simple sentence patterns. Of these primers, the most widely circulated were the Dick and Jane readers, in which elementaryschool students were introduced to the quintessentially suburban lives of Dick, Jane, and Sally, along with their cat Puff and their dog Spot.
By their very nature, primers use a limited vocabulary and a highly restricted sentence structure. Presumably, this makes them more easily understood by those who are just learning to read. If you look at the Dick and Jane style from the opposite perspective, this same simplicity of structure also makes this sort of text easier to write.
Let's imagine that you have been hired to write a program that can automatically produce a reader in the Dick and Jane series. As a first step toward solving this problem, you should take advantage of the fact that many of the sentences in the typical Dick and Jane story are drawn from a rather simple set of patterns. For example, as the characters are introduced, you usually see a sentence of the form
where the blank space is filled in with the appropriate name. ...
Get Thinking Recursively with Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.