Manipulating Character Strings

The judging commands -bump- and -put- operate on the judging copy of the student's response. It is sometimes useful to manipulate other strings of characters with -pack-, -move-, and -search-. These commands are regular commands, not judging commands. Like -showa-, they operate on stored character strings, not the judging copy of the student's response. These commands are mentioned here because they are often used in association with the analyzing of student responses. In particular, the judging command -stores- can be used to get the response character string. It can then be operated on with -move- and -search-. Finally, the altered character string can be loaded back into the judging copy with the judging command -loada- (load alphanumeric; the -loada- command is precisely the opposite of -storea-). Since this section deals with a rather esoteric topic, you might just skim through it now to get a rough idea of what character string manipulations look like. If you later find a need for such operations, you should study this section again.

Here is an example of a -move- statement:

move v3,5,v52,21,8

This means “move 8 characters from the 5th character of the string that starts in v3 to the 21st character of the string that starts in v52.” The 21st through 28th characters of the v52 character string are replaced by the 5th through the 12th characters of the v3 character string. The v3 character string is unaffected. In other words, -move- has the form:

move string 1,start1,string2,start2,#characters moved

If the number of characters to move is not specified, one character will be moved.

Here is an example of the use of -move-. Suppose the student types “x+4y = y-3”, and we want to convert this into the form “x+4y- (y-3)” before using -store- on it. Assume “str” has been defined:

arrow 1812 $$ x+4y=y-3 putd .=.-(. $$ x+4y-(y-3 storea str,jcount ok $$ to do regular -move- move ')',1,str,jcount+1 $$ x+4y-(y--3) judge continue $$ to do judging -loada- loada str,jcount+1 store result ok write Subtracting the right side of your equation from the left side gives ⊀s,result⊁.

In the -move- command the parenthesis within single quote marks, ')', means a character string one character long consisting of a right parenthesis. Similarly, `dog' would denote a character string consisting of d,o, and g. Character strings up to ten characters in length may be described this way, using single quote marks. The -move- command shown above moves the first character of ')', which is just a right parenthesis, to the (jcount + 1)th character position in “str”. This effectively appends a right parenthesis to the student's character string (as modified by the -putd-). The -loada- command moves the final character string into the judging copy so that -store- can operate on it. Note carefully the switches from the judging state to the regular state and back again.

The -search- command is used to look for occurrences of specific character strings. It has the form:

search string1,length1,string2,length2,start2,return --------------- --------------- ⇩ ⇘ string string ⇩ return location sought to look ⇩ through where to start

Suppose we use -storea- to place the unaltered student response “x+4y=y-3” in “str,jcount”. Then use:

search '=',1,str,jcount,1,charnum ⇩ ⇩ ---------- ⇩ ⇘ ⇩ ⇩ ⇘ ⇩ return location ⇩ ⇩ ⇘ start at ⇩ ⇩ ⇘ beginning ⇩ ⇩ ⇘ of string look for string = sign to look (string 1 through character long)

This -search- command will set the variable “charnum” to 5, since the equal sign is the 5th character in “x+4y—–y -3”. If the search is unsuccessful, “charnum” is set to -I. As further illustration of -move- and -search-, let's rewrite our earlier sequence without the -putd-:

arrow 1812 storea str,jcount ok search '=',1,str,jcount,1,charnum * Now make room for the -( : move str,charnum+1,str,charnum+2,jcount-charnum *Next insert the --( : move '-(',1,str,charnum,2 $$ move 2 characters * Append the ) : move ')',1,str,jcount+2 judge continue loada str,jcount+2 store result ok

The -search- finds the equal sign. The first -move- moves the latter part of the string to make room for the insertion of -c. The second -movemakes the insertion which overwrites the characters (=y) which were there originally. The third -move- appends the `r. Normally, the -searchwould be followed by a “goto charnum,noeq,x” to take care of the case where the student did not use an equal sign, in which case “charnum” would be -1.

The single quote marks can be used to specify character strings up to ten characters long. Longer character strings can be placed in variables with a -pack- command:

pack v11,v3,abcdefghijklmnopqrstuvwxyz ⇩ ⇘ string character count location

This packs a character string 26 characters long into v11 and following variables. The character count (26 in this case) is placed in v3. Since each variable holds ten characters, v11 and v12 will be full while v13 will have the last six characters. The -pack- command might be considered analogous to -storea-, since both place character strings in variables. In the case of -storea-, the total character count can be gotten from the systemdefined variable “jcount”. Here is another example:

. pack v12,v1,H2SO4 ••• showa v12,v1

This will display “H2S04” on the screen. The character count in vl will be ten, including three shift codes and two subscripts. The character string H2SO4 is actually composed of shift, h, subscript, 2, shift, s, shift, o, subscript, 4. The character count portion of a -pack- command can be left blank, as in “pack v12„dog”, the result of which could be displayed later with the statement “showa v12”. It is possible to embed “show” commands in a -pack- statement:

. pack string,count,There are ⊀s,total⊁ left. ••• showa v12,v1

There is also a conditional form, -packc-, analogous to -writec-:

packc cond,string,count,dog,cat,horse,cow ⇙ ⇩ ⇩ ⇩ ⇩ conditional -1 0 1 ≥2 expression

There are other string-oriented commands. For example, -clock- will get the time, -date- gets today's date, -name- gets the (18-character) name the student is registered under, and -course- gets the course the student is registered in. These commands are used in the following illustration:

name v1 $$ v1 and v2 for name course v3 clock v4 date v5 write Hello! Your name is ⊀a,v1,18⊁. You are registered in ⊀a,v3⊁. The time is ⊀a,v4⊁. The date is ⊀a,v5⊁.

Suppose the student is registered as “sam nottingham” in a course “french4.” It is 10:45:37 PM (22:45:37 on a 24-hour clock) on June 3, 1974. The student will receive this display:

Hello! Your name is sam nottingham. You are registered in french4. The time is 22.45.37. The date is 06/03/74.

All of these commands, -name-, -course-, -clock-, and -date-, simply place the requested character string in the specified variable for use in a -showa-.

The -clock- command produces a character string. In addition, there is a system variable “clock” which may be used in calculational expressions. It holds the number of seconds of a daily clock to the nearest thousandth of a second, and is convenient for calculating the amount of time spent in a section of a lesson.

The -date- command also produces a character string. There is also a -day- command which produces a number corresponding to the number of days elapsed since January 1, 1973. This number of days and fraction of a day is accurate to one-tenth of a second.

The TUTOR judging commands offer a great deal of power. We have seen that the judging commands -bump- and -put- together with the regular string-oriented commands -move-, -search-, and -pack- can be used to change an otherwise intractable response into a form which can be handled with TUTOR judging commands. This is a useful scheme as

long as only minor modifications are required. However, if major modifications of the response are required in order to be able to use TUTOR judging facilities, it is usually simpler to “do your own judging.” That is, get the student's response with a -storea- and then analyze it with string-oriented commands, together with the additional calculational machinery described in Chapter 9. You might not even want to use the built-in marker features of the -arrow- command, with the associated returns to the -arrow-, when there is a “no” judgment. In such circumstances you might write a subroutine to be used in place of -arrow- commands, which merely collects the student's response:

unit arrow(apos) arrow apos storea sstr,scnt jcount specs nookno ok endarrow

Instead of writing “arrow 1815” with associated judging commands you would then write:

. . . do arrow(1815) calc,move,etc. to do your own judging . . .

Naturally, this course of action is advisable only if you are trying to analyze responses which have a form very different from those classes of responses which can be handled well by TUTOR judging commands.

Catching Every Key: -pause-, -keytype-, and -group-