HP 3000 Manuals

Lesson 5: Expression Substitution [ MPE V to MPE XL: Getting Started ] MPE/iX 5.0 Documentation


MPE V to MPE XL: Getting Started

Lesson 5:  Expression Substitution 

Expressions are evaluated and variables are dereferenced implicitly
(without !)  in the commands CALC, ELSEIF, IF, WHILE, and SETVAR.
Expression evaluation and variable dereferencing are not done implicitly
in other MPE XL commands, but they can be done explicitly (with !).

You have already seen examples of implicit and explicit dereferencing.

Implicit Dereferencing (using no !) 
__________________________________________________________________
|                                                                |
|                                                                |
|      :SETVAR X,4                                               |
|      :SETVAR Y,X                                               |
|                                                                |
__________________________________________________________________

The value of X is assigned to the variable Y in the statement above
without the use of !  to dereference X.

Explicit Dereferencing (using !) 
___________________________________________________________________
|                                                                 |
|                                                                 |
|      :ECHO !X                                                   |
|      4                                                          |
|      :PRINT MYFILE!X                                            |
|                                                                 |
___________________________________________________________________

You must use !  to dereference the variable X in echoing 4 to the screen
and in printing the contents of MYFILE4 to the screen.

If you want to evaluate an expression in a command other than CALC,
ELSEIF, SETVAR, IF, and WHILE, you would use this syntax:  ![expression].

Example: 
_________________________________________________________________
|                                                               |
|                                                               |
|      :SETVAR a, 3 + 1                                         |
|      :ECHO a+2=![a+2]                                         |
|      a+2=6                                                    |
|                                                               |
_________________________________________________________________

In this example, note that the first expression in the ECHO line is not
evaluated.  The ECHO command itself does not allow for evaluation of
expressions.  However, when ![a+2] is encountered in the same command
line, it is evaluated and its value is substituted.

Exercises 

8.   Use each of the following commands to evaluate 3+2:   SETVAR, CALC,
     and ECHO.

9.   Use ECHO to evaluate the following, where X=24, Y=362, and Z=1000:
     (X + Y + Z - 252) * 4

10.  Write a command file that prompts you for your favorite year, and
     that uses the input in displaying the following (completed) sentence
     on the screen:

     Had you been born in the year _____, you would be _____ years old in
     the year 2010!

     (HINT: INPUT stores numeric data as a string, but the input can be
     converted to numeric data using SETVAR. However, you have to use
     explicit dereferencing--this is an exception to the rules you have
     just learned.)



MPE/iX 5.0 Documentation