Assignments can be made to variables, field references, pointers and arrays. Various assignments are describes according to the kind of information stored. The right hand side contains an Arithmetic Expression or a pointer reference. Type casts can be implicit or explicit type casts.
Transfer a value of a base type to a variable, field, or array element. The type of the Target is used to evaluate the Expression. Operands in the expression are implicitly cast to the type of the Target. Expliticit type cast functions can be applied to subexpressions.
Array indecies and many function arguments have established types. Array indecies are coerced to a Word. Function arguments are coerced to the type of their parameters. Some intrinsic functions adopt the type of their context as the type of the function and its arguments.
The type of an expression can be discerned by reading it from left to right. The type of a given operation can be determined unambiguously from its context. This obviates the need for mixed mode coersion tables for operators.
local B byte, P parcel, W word, R1 single, R2 single W = B + P * R :word{B} + (word{P} * word{R}) W = 100 * single(R1 - R2) :word{100} * word{ single{R1 - R2}} W = 50 / .01 :word{50} / word{.01} Causes division by zero! W = (-R * -5.5) * 2.1 :word{ single{ (-R * -5.5) * 2.1 }}
Care must be taken not to overflow this type when computing an index which has subexpression values that may cause an exception for this type. Consequently, it is advisable not to include such subexpressions in a range expression.
B[root(X^2 + Y^2)] = E :May overflow a Word array bound. User = User
Copies a variable containing a user defined type into the variable on the left. Both variables must be of the same user defined type.
Enumeration variables may be assigned to another enumerated variable of the same type, an eumeration constant, or an unsigned integer constant or value. Note that enumeration constants are designated with a leading dot.
Enum = Enum Enum = Byte Enum = Enum{ Byte } Enum = .Item Enum = Parcel Enum = Enum{ Parcel } Enum = Integer Enum = Word Enum = Enum{ Word } Enum = Cell Enum = Enum{ Cell } Shade = Favorite Shade = I Shade = Color{ I } Shade = .Red Shade = 0 Shade = Color{ 2 } Shade = 3 Shade = Color{ * }
Variables with enumerated types may also be coerced to Integer type. The integer value of an enumerated variable is either zero or the position of the current value in the declaration of its type. An exception may occur when coercing to a byte and the current position exceeds 255.
Byte = byte{Enum} Word = word{Enum} Parcel = parcel{Enum} Cell = cell{Enum}
The constant 0 can be assigned or compared for the null state. Other constants make sense only if integer type assignments are allowed. Micros can be assigned and in the case of ambiguity, the micro can be assigned. By limiting constants to 0 this is the only way ambiguity can lead to an error.
type E in one, Two, Three local Zero |= 0 E = 0 :Assign 0. E = Zero :Assign 0. E = .One :Assign 1. Array[Index] = Expression :Assign a value to an array element. Array[Index] = Structure :Copy a structure to an array element.
An operator can precede the equal sign in an assignment to perform the
designated operation. It is applied between the target and the right hand side
expression and the result is stored in the target.
For a real number assignment operators limited to:
I += 1 I = I + 1 S ^= 2 S = S ^ 2
Pointer = @Pointer Set to a pointer of the same type. Pointer = @cast{ Pointer } Set to a pointer; bypassing type checking. Pointer = @cast{ Variable } Set to the address of a variable; bypassing type checking. Pointer = @Function( Argument, ... ) Set to a function returning a pointer. Pointer = @Constant Set to a 16 bit unsigned integer (may be a Micro). Pointer = @parcel( Integer ) Set to a 16 bit unsigned integer expression. Pointer = @Name[Index] Point at an element in an array. Pointer[Index] = Expression Set a referenced array element to a value.
Pointers can be used in inequalities to compare if they are equal, not equal, or null. A null pointer in assignments is coded, "@0". You can set the pointer to any 16 bit integer. hex? micro?
Pointer = @0; Assignin null to a pointer. IF @Pointer = 0: See if a pointer is null. IF Parcel{ @Pointer } See if a pointer has a non-zero Parcel value. IF Parcel{ @Pointer } = 0 See if a pointer is null or holds an address. Pointer = @Decimal Assign a 16 bit unsigned decimal value. Pointer = @parcel{ Integer } Assign a 16 bit unsigned integer expression. Pointer = @cast{ Pointer } Cast a pointer of one type to another. Pointer = @Function( Argument, ... ) Assign a pointr returned from a function.
You can also conditionally assign a variable, field, or array element to a value. Pointers cannot be conditionally assigned as it is too easy to make a mistake.
Target = if Condition, True, False Target = if Condition, True Target = if Condition
If the Condition is met then the True expression is assigned. Otherwise the False expression is assigned. If no True or False clause is coded the result is 1 if true or 0 if false.
X = if A = 0, 5, 2 If A = 0 then X = 5 else X = 2 X += if A = 0, 5, 2 If A = 0 then X = X + 5 else X = X + 2 X = if A = 0, 5 If A = 0 then X = 5 X += if A = 0, 5 If A = 0 then X = X + 5 X = if A = 0 If A = 0 then X = 1 else X = 0 X += if A = 0 If A = 0 then X = X + 1 else X is unchanged
When an Operator assignment is coded it is applied to the target value.
Target Operator= if Condition, True, False Target Operator= if Condition, True Target Operator= if Condition
The append (!) and division operators
C != if A = B The compiler issues an error. C /= if A = B The compiler issues an error. C _/= if A = B The compiler issues an error. C %= if A = B The compiler issues an error. True False C += if A = B C = C + 1 C is unchanged C -= if A = B C = C - 1 C is unchanged C //= if A = B C = C // 1 C is unchanged C \\= if A = B C = C \\ 1 C is unchanged C >>= if A = B C = C >> 1 C is unchanged C <<= if A = B C = C << 1 C is unchanged C --= if A = B C = C -- 1 C is unchanged C \/= if A = B C = C \/ 1 C is unchanged C /\= if A = B C = C /\ 1 C = 0 C *= if A = B C is unchanged C = 0 C _*= if A = B C is unchanged C = 0 C ^= if A = B C is unchanged C = 1