Skip to main content Accessibility help
×
Hostname: page-component-8448b6f56d-mp689 Total loading time: 0 Render date: 2024-04-23T12:15:54.902Z Has data issue: false hasContentIssue false

Program 5 - Wild Words

Published online by Cambridge University Press:  05 July 2014

Get access

Summary

This program simulates the familiar attempt by a chimpanzee to type one of the works of Shakespeare. It illustrates a number of aspects of the use of the predefined library for string handling and generating random numbers.

The idea is that the chimp types away basically at random. However, the magic word processor knows of certain characteristics of English text such as the frequency of letters.

Various checks ensure that only certain oneand two-letter words are possible; and of course certain four-letter words are forbidden. Words are also rejected if they start with an unacceptable pattern, have no vowels or have no consonants.

The text is processed as a series of unjustified lines of words with parameters such as a maximum line length of 70 characters. The text is structured into sentences and paragraphs. The stop is the only punctuation mark.

After a set number of lines have been typed, the program searches for names that might occur in a play such as Hamlet, Lear, Puck and so on. If successful it types a friendly message for the chimp and then prints the story, otherwise it types a less friendly message and tries again.

Characters are drawn from a conceptual infinite bag containing characters in the correct proportion. Word, sentence and paragraph length are given by rolling an associated pair of conceptual dice as required. After a word is completed it is checked for feasibility. If accepted, it is added to the story.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2014

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Wild Words
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.034
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Wild Words
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.034
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Wild Words
  • John Barnes
  • Book: Programming in Ada 2012
  • Online publication: 05 July 2014
  • Chapter DOI: https://doi.org/10.1017/CBO9781139696616.034
Available formats
×