# CDC Community

🔹 Historical Conservation 🔹

### Site Tools

tutor:variable_names

# Giving Names to Variables: -define-

Your programming can be made much more readable by “defining” suitable names for the student variables which you use. For example, in the units just discussed, the quantities of interest were the center (x and y) and radius of the circular arc. We should precede such units with a -define- statement:

define x=v1,y=v2 radius=v3 \$\$ names may be 7 characters long unit vary calc x⇦150 y⇦300 \$\$ The command name -calc- may be radius⇦100 \$\$ omitted on successive lines do halfcirc calc x⇦x+radius do halfcirc unit halfcirc at x,y circle radius,0,180 draw x-radius,y;x+radius,y

The -define- statement tells TUTOR how to interpret the defined names when they are encountered later in expressions. The units are now much more readable than they were when we used vl, v2, and v3.

Giving meaningful names to the variables you use is very important. After an absence of several months, you would have difficulty in remembering what you are keeping in, say, variable v26, whereas the name “tries” would remind you immediately that this variable holds a count of the number of times the student has tried to answer the question. The importance of readability is even more vital if a colleague is working with you on the material. Your associate would find it extremely frustrating to try to figure out what you are keeping in v26. So, use -define-!

There should not be any v3's or v26's anywhere in your lesson except in the -define- statement itself. Put all your definitions at the very beginning of the lesson where you will have ready reference to the variables you are using.

The only reason we started out using the primitive v-names was to establish a more concrete feeling for the meaning of a student variable. From here on we will use defined variable names. A preceding -definestatement is assumed.

WARNING: Normal algebraic notation permits expressions such as “rcosθ”, but in TUTOR you must write “r×cos(θ)” or “r(cos(θ))”. That is, you must use an explicit multiplication sign between names (either your defined names such as “r” or TUTOR-defined names such as “cos”), and you must place parentheses around the arguments of functions. For example, the “θ” in cos (θ) must be enclosed in parentheses.

The reason for this is that TUTOR cannot cope with the ambiguities of trying to decide whether an expression such as “abc” means “a×bc” (if there is a name “bc”), or “ab×c” (if there is a name “ab”), etc. Later, when we discuss the important topic of judging student responses, we will see that TUTOR can make reasonable guesses when treating a student's algebraic response and can permit the student the luxury of leaving out multiplication signs and omitting parentheses around function arguments. You, the author, are required to be more explicit, however, in separating one name from another. Notice that “17angle” is fine and TUTOR will recognize this as meaning “17×angle”. But “rangle” can't be pulled apart into “®(angle)” because you might have meant “(ran)(gle)”.

tutor/variable_names.txt · Last modified: 2022/08/25 14:31 by 127.0.0.1