REXX Expressions & Operators
We need to do something with our REXX scripts. The way we do this is with expressions and operators. For example, we frequently need the script to remember a value for later reuse. In algebra, we might say a = 7. In REXX, we do almost the same thing: dishesWashed = 7.
These examples were both variable assignment. We took a value and said we wanted to store it in a variable. A variable is named that because its value can vary. In each case above, the variable holds a value of 7. One difference between variables in algebra and variables in REXX is REXX variables work out to being code-names for particular spots in the computer's memory. We never have to know that the variable banana is found at the corner of Main Street and I Avenue--the computer takes care of all that for us.
The Kilowatt Software REXX tutorial's page on expressions has some examples and discussion that is helpful. When you are learning REXX, I suggest that you start out by having the tutorial site open while you work. This is what I have been doing.
In algebra, operator precedence is frequently described by using "My Dear Aunt Sally". This is a memory aid to teach you that multiplication goes before division (actually, they are of equal precedence), followed by addition and subtraction (again, addition and subtraction are actually of equal precedence). In REXX, the algebraic precedence is only part of the full precedence chain.
Kilowatt's tutorial tells us that "prefix operators" (such as + [positive], - [negative] and the two ways of entering the NOT operator ¬ and \), are followed by the power (exponent) operator, followed by multiplication and division, followed by addition and subtraction, followed by concatenation (taking two pieces of data and forming one long text string out of them), followed by comparison, followed by the AND operator, followed by the OR operators. All this means is that if an expression contains more than one of these operators, the work will be performed by doing the highest precedence operations first (from left to right), then dropping to the next level of precedence. Parentheses [( and )] can be used to change the order, since whatever is inside of parentheses goes before any of the operators.
I do not know if I made it clear. Just remember, when you took algebra, there was a certain order that you did operations in, so that consistent results could be obtained. REXX's operations follow a similar order, for the same reason. If they didn't do this, we could have different results to an expression, depending on whether we were using Open Object REXX, Regina, or ROO.
I encourage you to walk through this tutorial, trying out different ways to use expressions and operators. Use the SAY instruction to see what your results are.


0 comments:
Post a Comment
All comments are moderated. Your comment will show up after approval.