Assignment

Purpose

Having a place to put everything is a good start for getting organized, however no progress is made until those storage areas get used. Assignment is one of the main ways information gets placed into a storage area. This section explains assignment for simple types and the implications of assignment for advanced types.

Assignment of Simple Types

The standard assignment operator is a colon followed by an equals sign. For example the variable DrillDepth, a longint, might be assigned with the statement:

DrillDepth:=500;

There has been provision made for programmers familiar with Basic so an equals sign by itself is also allowed:

DrillDepth=500;

The semicolon at the end of the statement indicates that the programmer believes the statement to be complete. The language does not strictly enforce that the semicolon if what is being written is unambiguous but it is good practice to have it there.

Assignments to single or doubles types allows the use of a period to indicate the decimal point, i.e.

FractionalUserVariable:=6.5;

Strings may be assigned by using single quotes or double quotes but the beginning and end must be the same. The following two statements are allowed:

MachineStatus:=’Ready’; MachineStatus:="Ready";

Starting with a single one type of quote permits the other type of quote to be in the string such as this:

That program produces this result:

Upper and lower case letters in string constants are kept distinct. Note that although the hardcopy of the manuals (or even this page) may show a ?back quote? for the leading quote this is a result of the printer that produced the documentation. The intended symbol is always the conventional single quote, most often found under the double quote to the right of the semicolon and the left of the enter key.

Variables may be assigned from another variable, i.e.

CurrentPosition:=LastPosition;

Variables of the same type may always be assigned. Variables of different types are converted automatically in certain cases. A longint can be assigned from an integer. The integer always fits. An integer may be assigned from a longint however some information may be lost. It is the your responsibility to make sure you are not assigning a value beyond the integer range. Singles and doubles may be assigned to integers only after using the ?ROUND? or TRUNC operation, i.e.

MyInteger:=Round(MyRealSingle);

Integers and longints may be assigned to singles and doubles how- ever it is the programmer?s responsibility to insure they will properly fit into the range of the chosen floating point type. Single precision floats have a 24 bit mantissa and so will lose information assigned from a very large 32 bit number. Doubles can hold most anything.

Assignment of Aggregate Types

Aggregate types are often assigned on a component by component basis. For example a variable named HomePositionVector of type T3Vector might be assigned with the statements:

HomePositionVector.X:=500;
HomePositionVector.Y:=600;
HomePositionVector.Z:=700;

Because this is tedious most object aggregates include procedures that consolidate assigning all of the object component values into a single statement, usually named Init. The same 3 dimensional vector from the previous example may be assigned in a single statement:

HomePositionVector.Init(500,600,700);

When used in assignment statements all of the components of the source object or record (on the right side) are copied into the corre- sponding components of the destination (on the left side). For example if the following symbols were 6 dimensional vectors of type T6Vector this statement would copy 6 longints:

TaughtPositionVector:=CurrentPositionVector;

When records or objects are copied in this manner there is never any type conversion. Records and objects in an assignment statement must be of the same type.