Purpose
Beyond merely shuffling information from one place to another, organization is accomplished by combining and operating on items to produce new items.
This section describes common infix operators.
Operators for simple types
There are a variety of different infix operators. Infix means that
expressions are written in a ?conventional math? format with the
operator in between the two parameters it relates to. For example to
add two variables and assign them to a third is done with:
Sum:=Operand1+Operand2;
Spaces are not required between the operator and the operands. A
frequently encountered need is to increment a variable by one. In
pascal this is usually done with the command:
NumberOfPartsCompleted:=NumberOfPartsCompleted+1;
In this particular case the compiler recognizes that the destination of this
operation and the source are the same and that the amount being added is one.
This becomes a native increment instruction for the processor.
Infix Operations include
+ Addition operator
- Subtraction operator
* Multiplication operator
*
div integer division
/ floating point division, i.e. fractional
and logical and operator
or logical or operator
xor logical exclusive or operator
Operations may be grouped with parenthesis to explicitly control
precedence, i.e.
Answer:=(A+(B*C));
would be a different answer from:
Answer:=(A+B)*C);
Multiplication and division have
higher precedence than addition and subtraction however
being explicit is often much clearer.
const PartsInBatch=75;
All of the places that were concerned with the number of parts in a
batch are now automatically updated. The places where there might have been
49s or 51s now become PartsInBatch-1 and PartsInBatch+1.
It may appear that this is less efficient because of the additional
operations taking place to calculate that value however this is not a
problem. The compiler is aware that the expression PartsInBatch+1
is composed of values all known at compile time so the compiler
itself performs the calculation once creating the 51s and 49s (or 76s
and 74s if the PartsInBatch is 75). Using constants allows you to
centralize a machine attribute and derive other values from it to
manage application information. If a numerical value is used in more
than one place for the same meaning use a constant to insure these
two values ?stay in synch? in the event of a future change.
An important place for constants is in array bound declarations.
Arrays are often used to store information about the motion system
during data collection. It is very important that an array is not accessed beyond bounds.
Accordingly whatever procedure is filling the array should
use constants to indicate the range of filling which are the same
constants used to define the array size. This insures that as the array
size is altered that the filling operation is automatically altered as well
to insure consistency. Note that symbolic names may be typed into
the lower bound and upper bound fields in the variable declaration
dialog box: