REUSE(dyn.array.expr)
Description
The UniBasic REUSE function affects the application of arithmetic operations on dynamic arrays.
When REUSE Is Not Used
When you execute an arithmetic operation on an array and you do not include the REUSE function, one of the following happens:
■Array and constant – When you apply an arithmetic operation to an array and a constant, the operation is executed against only the first element of the array. If you want the operation to execute on every element in the array, apply REUSE to the constant.
■Two arrays – When you execute an arithmetic operation on arrays of different lengths, the operation is performed on the number of elements in the shortest array only. The remaining elements are each filled with 1 or 0, depending on the operation performed:
■Division – 1.
■Addition, subtraction, and multiplication – 0.
If you apply REUSE to the shorter array, the last element in this array is used to perform the operation on the remaining elements in the longer array.
1-690 UniBasic Commands Reference
Examples
In the following example, the program segment multiplies the arrays without using the REUSE function:
VIEWERS = 100:@VM:200:@VM:300
COST = 40:@VM:1
VCOST = VIEWERS*COST
This results in:
VCOST = 4000:@VM:200:@VM:0
VCOST takes its length from VIEWERS, the longest of the two arrays, but multiplication is performed on only the first two elements of each array because the other array, COST, has only two elements. The final element in the result array (VCOST) is filled with 0. 0 is used to fill because the arithmetic operation is multiplication.
However, if you apply the REUSE function to the shorter array:
VCOST = VIEWERS*REUSE(COST)
This results in:
VCOST = 4000:@VM:200:@VM:300
The final element in COST (1) is used to multiply with the final element of VIEWERS and fill the final element of the result array, VCOST.
No comments:
Post a Comment