|
OCaml Assignment: Pig Latin
Fall 2000, David Matuszek, Villanova
University
|
Your assignment is to write an OCaml function latinize S
to translate an English sentence S (represented as a string) into
Pig Latin. For example,
- latinize "when the cats away the mice will play";;
> "enwhay ethay atscay awayhay ethay icemay illway ayplay"
The rules for translating into Pig Latin are:
- If a word begins with a vowel, add "
hay" to the end of the
word. For example, "apple" becomes "applehay."
(One dialect uses "yay" rather than "hay;" if you
would rather do it this way, that's fine too.)
- If a word begins with one or more consonants, move those initial consonants
to the end of the word and add "
ay." For example, "strength"
becomes "engthstray."
- Special case: If a word consists of only consonants (e.g. "
try"),
just add "hay" to the end.
Simplifying assumptions:
- Don't worry about capital letters; everything can be
lowercase.
- Don't use any punctuation.
- Use single spaces to separate words.
- Always treat "y" as a consonant.
Hints:
- OCaml is interactive; play with it. Get used to it a little before you try
to do any serious work. This will help a lot when you try to actually start
using it.
- Write little functions, one at a time, and test each one out before writing
the next one. This is a good technique in any language, but is especially
important in OCaml.
- If you can't keep your functions small, at least build them up and test
them a line or two at a time. Otherwise you'll have a big function with an
error in it somewhere that you just can't find.
Extra credit:
- Handle capital letters correctly, e.g.
"When..." becomes
"Enwhay..."
- Retain the punctuation used in the original.
- Treat "y" as a consonant only if it is the first letter of a word;
otherwise, treat it as a vowel.
Turn in:
- A floppy with a proper label on it, and your name on the label, containing
the program in a file named
latin.ml. You can include a file
named readme.txt if there is anything in particular you want
to tell us about.
- No paper, please!
Due dates: July 26 (Final exam date). No late programs, no extensions.