REXX - Syntax - Keyword Instructions - INTERPRET

INTERPRET

The INTERPRET instruction evaluates its argument and treats its value as a REXX statement. Sometimes INTERPRET is the clearest way to perform a task, but it is often used where clearer code is possible using, e.g., value.


/* a touch of LISP */ X = 'square' interpret 'say' X || '(4) ; exit' SQUARE: return arg(1)**2

This displays 16 and exits. Because variable contents in REXX are strings, including rational numbers with exponents and even entire programs, REXX offers to interpret strings as evaluated expressions.

This feature could be used to pass functions as function parameters, such as passing SIN, COS, etc. to a procedure to calculate integrals.

Note that REXX offers only basic math functions like ABS, DIGITS, MAX, MIN, SIGN, RANDOM, and a complete set of hex plus binary conversions with bit operations. More complex functions like SIN had to be implemented from scratch or obtained from third party external libraries. Some external libraries, typically those implemented in traditional languages, did not support extended precision.

Later versions (non-classic) support CALL variable constructs. Together with the built-in function VALUE, CALL can be used in place of many cases of INTERPRET. This is a classic program:

/* terminated by input "exit" or similar */ do forever ; interpret linein ; end

A slightly more sophisticated REXX calculator:

X = 'input BYE to quit' do until X = 'BYE' ; interpret 'say' X ; pull X ; end

PULL is shorthand for parse upper pull

Likewise, ARG is shorthand for parse upper arg

The power of the INTERPRET instruction had other uses. The Valour software package relied upon REXX's interpretive ability to implement an OOP environment. Another use was found in an unreleased Westinghouse product called Time Machine that was able to fully recover following a fatal error.

Read more about this topic:  REXX, Syntax, Keyword Instructions

Famous quotes containing the word interpret:

    The common behavior of mankind is the system of reference by means of which we interpret an unknown language.
    Ludwig Wittgenstein (1889–1951)

    Philosophy is written in this grand book—I mean the universe—
    which stands continually open to our gaze, but it cannot be understood unless one first learns to comprehend the language and interpret the characters in which it is written. It is written in the language of mathematics, and its characters are triangles, circles, and other geometrical figures, without which it is humanly impossible to understand a single word of it.
    Galileo Galilei (1564–1642)

    If art has a purpose, it is to interpret life, reproduce it in fresh visions.
    Catherine Drinker Bowen (1897–1973)