Finding Key Words: The -match- and -storen- Commands
The -match- command, a judging command, makes it easy to look for key words in a student's response. The -match- command will not only find a word in the midst of a sentence, but it will replace the found word in the judging copy with spaces, to facilitate the further use of additional judging commands (including -match-) to analyze the remainder of the response. Here is the form of a -match- statement:
Here “num” is a variable which will be set to -1 if none of the listed words appear in the student's response, to 0 if “dog” appears, to 1 if “cat” or “feline” is present, 2 if “horse” is in the response, etc. In any case, -match- terminates judging, with a “no” judgment if num= -1 or an “ok” judgment otherwise. What if more than one of the words appear in the student's response? Suppose the student says:
There are many other ways in which the -match- can be utilized. First, we can improve greatly on our cursor program:
Unit “move” remains unchanged except to replace (in two places) the expression “anscnt -2” by the expression “num-1” (and we can delete the “judge ignore” in unit “move”). We see that -match is useful for converting a word to a number which represents the word's position in a list.
Another good use of -match-.is in an index:
Notice that we must increment “chapter” by one if we want topic “a” to be chapter 1, since -match- associates 0 with the first element in its list (-1 is reserved for the case where no match is found). If no match is found, there is a “no” judgment. (Again, -base- could come later in the unit, or at the beginning of the chapters, in which case the BACK key would still be active for returning to the place from which the index was accessed.)
These applications barely scratch the surface of -match-s capabilities. Here are some other ideas on how to use -match-:
- Use -match- to pull out 'negation words such as no, not, never, etc. Then “judge continue” and use -answer- or -conceptcommands to analyze the remainder of the response. You can in this way separate the basic concept from whether it is negated, with the negation information held in the -match- variable for easy use in conditional statements.
- Use -match- to identify and remove a key-word directive before processing the rest of the information. This comes up in simulating computer compilers, in games (“move” or “capture”), etc.
A related command is -storen-, which will find a simple numeric expression in a sentence, store it in your specified variable, and replace the expression with spaces. This is particularly useful for pulling out several numbers. The -store- command will handle much more complicated expressions including variables as well as numbers, but can get only one number. For example, the student might respond to a question about graph-plotting coordinates with “32.7,38.3”. These two numbers can be acquired by:
Like -store-, -storen- will terminate judging on an error condition (in which no number was found). In the example, the first -storen- removes and stores one number in “x” and the second -storen- looks for a remaining number to store in “y”. The first -storen- will terminate judging if there are no numbers. The second -storen- will terminate judging if there is no number remaining after one has been removed. The blank -answer- will be matched if only punctuation, such as commas, remains after the actions of the two -storen-s.