INTERPRET

>>-INTERPRET--expression--;------------------------------------><

INTERPRET processes instructions that have been built dynamically by evaluating expression.

The expression is evaluated to produce a character string, and is then processed (interpreted) just as though the resulting string were a line inserted into the program and bracketed by a DO; and an END;.

Any instructions (including INTERPRET instructions) are allowed, but note that constructions such as DO...END and SELECT...END must be complete. For example, a string of instructions being interpreted cannot contain a LEAVE or ITERATE instruction (valid only within a repetitive loop) unless it also contains the whole repetitive DO...END or LOOP...END construct.

A semicolon is implied at the end of the expression during execution, if one was not supplied.

Examples:

/* INTERPRET example */
data="FRED"
interpret data "= 4"
/* Builds the string  "FRED = 4" and        */
/* Processes:  FRED = 4;                    */
/* Thus the variable FRED is set to "4"     */
/* Another INTERPRET example */
data="do 3; say "Hello there!"; end"
interpret data        /* Displays:          */
                      /*  Hello there!      */
                      /*  Hello there!      */
                      /*  Hello there!      */
		      

Notes:

  1. Labels within the interpreted string are not permanent and are, therefore, an error.

  2. Executing the INTERPRET instruction with TRACE R or TRACE I can be helpful in interpreting the results you get.

    Example:

    /* Here is a small Rexx program. */
    Trace Int
    name="Kitty"
    indirect="name"
    interpret 'say "Hello"' indirect'"!"'

    When this is run, you get the following trace:

         3 *-* name="Kitty"
           >L>   "Kitty"
           >>>   "Kitty"
         4 *-* indirect="name"
           >L>   "name"
           >>>   "name"
         5 *-* interpret 'say "Hello"' indirect'"!"'
           >L>   "say "Hello""
           >V>   INDIRECT => "name"
           >O>   " " => "say "Hello" name"
           >L>   ""!""
           >O>   "" => "say "Hello" name"!""
           >>>   "say "Hello" name"!""
         5 *-* say "Hello" name"!"
           >L>   "Hello"
           >V>   NAME => "Kitty"
           >O>   " " => "Hello Kitty"
           >L>   "!"
           >O>   "" => "Hello Kitty!"
           >>>   "Hello Kitty!"
    Hello Kitty!

    Lines 3 and 4 set the variables used in line 5. Execution of line 5 then proceeds in two stages. First the string to be interpreted is built up, using a literal string, a variable (INDIRECT), and another literal string. The resulting pure character string is then interpreted, just as though it were actually part of the original program. Because it is a new clause, it is traced as such (the second *-* trace flag under line 5) and is then processed. Again a literal string is concatenated to the value of a variable (NAME) and another literal, and the final result (Hello Kitty!) is then displayed.

  3. For many purposes, you can use the VALUE function (see VALUE) instead of the INTERPRET instruction. The following line could, therefore, have replaced line 5 in the previous example:

    say "Hello" value(indirect)"!"

    INTERPRET is usually required only in special cases, such as when two or more statements are to be interpreted together, or when an expression is to be evaluated dynamically.

  4. You cannot use a directive (see Directives) within an INTERPRET instruction.