Expression Substitution [ Command Interpreter Access and Variables Programmer's Guide ] MPE/iX 5.0 Documentation
Command Interpreter Access and Variables Programmer's Guide
Expression Substitution
Variables are dereferenced implicitly when used in the SETVAR, IF, WHILE,
and CALC commands. Variables within an expression are also implicitly
dereferenced. A variable can be implicitly dereferenced in any command,
therefore, by including it in an expression.
The result of an expression, however, must be dereferenced explicitly.
To do this, the expression is enclosed in brackets and preceded by an
exclamation point. By explicitly dereferencing the expression and using
implicit dereferencing of variables within the expression, the expression
is more readable. The following examples demonstrate the use of explicit
and implicit dereferencing when using expressions.
:BUILD X;REC=![-2*40]
:BUILD Y;DISC=![FINFO(FILE1,'EOF')*110]
:ECHO ![UPS(FILE1)] does not exist.
Expressions are evaluated from left to right within the operator
hierarchy. This sequence can be altered, however, by including
parentheses in the expression. Parentheses can be nested to provide a
specific sequence for evaluation.
The following example shows the expression that centers the variable TEXT
on an 80-character line. Note that TEXT is implicitly dereferenced
within the brackets and explicitly dereferenced outside the brackets.
:ECHO ![RPT(" ",(80-LEN(TEXT))/2)]!string
In this example, a string is centered on an 80-character line by
repeating the spacing character a number of times and concatenating the
original string to it. Note the use of parentheses to override operator
hierarchy and compute results in the proper sequence.
1. Evaluates the length of the string named TEXT.
2. Subtracts this length from the width of the line (80 characters).
3. Divides the remaining number of characters by 2.
4. Repeats the spacing character the specified number of times.
5. Dereferences the expression results.
6. Concatenates the expression results to the original string.
MPE/iX 5.0 Documentation