Alphanumeric to Numeric: The -compute- Command
The -store- command analyzes the judging copy of the student's response character string and produces a numerical result. This is actually a two-step process. First, the character string is “compiled” into basic computer instructions and then these machine instructions are “executed” to produce the numerical result. During the compilation process the “define student” definitions and the built-in function definitions (sin, cos, arctan, etc.) are used to recognize the meaning of names appearing in the character string. Numbers expressed as alphanumeric digits are converted to true numerical quantities. For example, the character string 49 becomes a number by a surprisingly indirect process. The character code for “4” is 31 since “z” is 26, “0” is 27, etc. The character code for “9” is 36. The number expressed by typing 49 is obtained from the formula:
10(31-27)+(36 27) or 10("4"-"0")+("9"-"0") 10(4)+(9) 40+9 49
For these and similar reasons, the compilation process is ten to a hundred times slower than the execution process. Therefore, TUTOR attempts to compile the student's response only once, while the resulting machine instructions may be used many times.
The first -store-, -ansv-, -wrongv-, -storeu-, -ansu-, or -wrongucommand encountered during judging triggers compilation. All these commands following the first one simply reuse the compiled machine instructions. If a -bump- or -put- makes any changes in the judging copy, a following -store- or related command will have to recompile. Similarly, a “judge rejudge” will force recompilation by any of these commands. Note that re-execution is always performed even if recompilation isn't, because the student might refer to defined variables whose values have been altered.
While -store- will compile and execute from the judging copy, the regular -compute- command will compile and execute from any stored character string:
After compilation, the “pointer to machine instructions” contains the location of the machine instructions in a special -compute- storage area. You must zero the pointer at first to force compilation. TUTOR will then set the pointer appropriately, so that re-executions of the -computecommand can simply re-execute the saved machine instructions. Here is a unit which permits the student to plot functions of interest to him or her.
Different functions can be superimposed by changing the response instead of pressing NEXT or BACK. The first -compute- in this unit calculates the value of the student's function for x equal to zero. The -gat command positions us at location (0, result) so that the first -gdraw- will draw a line starting at that point. The system variable “formok” has the value -1 if compilation and execution succeed; 0 if compilation succeeds but execution fails (due to such errors as trying to take the square root of a negative number); and various positive integral values for various compilation errors (missing parentheses, unrecognized variable names, etc.).
Note that predefined functions can be more easily plotted with a -funct- command. For example, the student could specify a value for “n”, and you could plot a polynomial simply by using “funct” xn,x⇐,10,.1“. But, you must use -compute- if the student is permitted to try arbitrary functions of his or her own choosing.
As another example, the PLATO lesson “grafit” (written by this author) permits the student to write up to fifteen statements in the grafit language and execute his or her program to produce graphical output (as seen in Fig. 10-6):
This student's program calculates the motion of a mass oscillating on the end of a non-standard spring. The two curves are the superposition of running the program twice with different values of the parameters. The heart of this lesson is a loop through a -compute- command with string, character count, and point all being indexed variables. The index is the line number, from 1 to 15. Each student response is analyzed using a -match- command looking for keywords such as “goto”. Then the rest of the response is filed away with a -storea- into the string storage area corresponding to that line number. The 15 pointer variables are zeroed in the “ieu” (initial entry unit) to insure that when the student returns to a PLATO terminal after several days TUTOR won't be confused over whether the strings have been recently compiled or not. Also, whenever the student changes one of his or her statements, the corresponding pointer is zeroed in order to force recompilation of the altered character string. The student can press DATA to initialize parameters, LAB to specify what variable to plot against what variable, and HELP for a description of the grafit language. The student define set defines all 26 letters as variables the student can use.
Note that even though s, i, and n have been defined in the student define set, the student can use the “sin” function. The reason that the student's “sin” is not interpreted as sxixn is that TUTOR looks for the longest possible name in a string of characters typed by the student. One difference between the handling of student expressions and author expressions is that students cannot reference system variables such as “where”, “anscnt”, or “data” (the numerical value of the DATA key). If you want the student to be able to use “where”, define it in the student define set as “where—-where”. While authors are discouraged from using primitive names such as v47 (except in a -define- statement), students are not permitted to use primitives at all. This is done to protect the author's internal information. Similarly, students cannot use the assignment symbol (⇐) except in a -compute-, unless there is a “specs okassign”.
It should be mentioned that while -compute- converts alphanumeric information into a numerical result, there is an -itoa- command that can be used to convert an integer to an alphanumeric character string. Most often, however, the -pack- command with embedded -show- commands will be used to convert non-integer as well as integer values to the corresponding character strings.