# spell :: filedescriptor X string -> boolean proc spell {fd word} {...}It should take a file descriptor, which refers to an opened dictionary file, and a string, which is the word to be checked, and it should return 1 if the word is spelled correctly, or 0 if not.
We define spelled correctly to mean that the word is listed in the dictionary file. We ignore the issues of plurals, etc: if the exact word is not found in the dictionary, it's misspelled.
We define a dictionary file to be any file that contains words, one
per line, which is sorted in ASCII collating order. You may use the
file /home/keith/web/tcl-course/words
for testing.
Hint: this proc is extremely easy to write. If you disagree, you're approaching it wrong.
/usr/dict/words
. Why doesn't this file work if you use
it with your spell proc? What type of changes would you have to make
to your code to be able to use this file as is?
spell
proc you coded above (and my dictionary).
Your program should read a file to be spell checked on standard input,
and write to standard output any mispelled words, one per line.
You can use any rule you like for deciding what makes a word in the input file. I recommend choosing a rule that exploits existing Tcl commands.
To run your program (assuming it's called spell.tcl
), you
can say, from the Unix shell:
megatcl -f spell.tcland then you can type lines of text to be spelled checked; type
C-d
alone on a line to terminate. You can also spell
check a file by saying:
megatcl -f spell.tcl < filename
Don't worry about the problems of uppercase vs lowercase, or punctuation marks. We'll learn how to handle these when we cover string processing.
Hint: this program, not counting comments, whitespace or lines
containing closing braces, and not counting the code for your
spell
proc, should be about six lines long.
Hint: this should add about two lines to your program.