Rexx is widely used as a glue language, macro language, and is often used for processing data and text and generating reports; these similarities with Perl mean that Rexx works well in CGI programming and it is indeed used for this purpose. Rexx is also used as an internal macro language in some software including the ZOC terminal emulator. Additionally, the Rexx language can be used for scripting and macros in any programme which uses Windows Scripting Host ActiveX scripting engines languages (e.g. VBScript and JScript) if one of the Rexx engines (see below) are installed.

Rexx is supplied with OS/2 versions 2.0 and up and Rexx script for OS/2 have the filename extension .cmd, as do shell scripts as is the case with Windows NT type operating systems—the first line of the script determines which it is.

does not fully support Unix style command line parameters (except specific implementations)

does not provide basic terminal control as part of the language (except specific implementations)

does not provide a generic way to include functions and subroutines from external libraries (except specific implementations)

REXX has just twenty-three, largely self-evident, instructions (e.g., call, parse, and select) with minimal punctuation and formatting requirements. It is essentially an almost free-form language with only one data-type, the character string; this philosophy means that all data are visible (symbolic) and debugging and tracing are simplified.

REXX syntax looks similar to PL/I, but has fewer notations; this makes it harder to parse (by program) but easier to use.

History

REXX was designed and first implemented, in assembly language, as an ‘own-time’ project between 20 March 1979 and mid-1982 by Mike Cowlishaw of IBM, originally as a scripting programming language to replace the languages EXEC and EXEC 2[1]. It was designed to be a macro or scripting language for any system. As such, REXX is considered a precursor to Tcl and Python. Rexx was also intended by its creator to be a simplified and easier to learn version of the PL/I programming language.

It was first described in public at the SHARE 56 conference in Houston, Texas, in 1981[2], where customer reaction, championed by Ted Johnston of SLAC, led to it being shipped as an IBM product in 1982.

The Amiga version of REXX, called ARexx was included with AmigaOS 2 onwards and was popular for scripting as well as application control. Many Amiga applications have an "ARexx port" built into them which allows control of the application from Rexx. One single Rexx script could even switch between different Rexx ports in order to control several running applications.

Several freeware versions of REXX are available. In 1992, the two most widely-used open-source ports appeared: Ian Collier's REXX/imc for Unix and Anders Christensen's Regina (later adopted by Mark Hessling) for Windows and Linux. BREXX is well-known for WinCE and PocketPC platforms.

In 1996 ANSI published a standard for REXX:
ANSI X3.274–1996 “Information Technology – Programming Language REXX”. More than two dozen books on REXX have been published since 1985.

Since the mid-1990s, two newer variants of REXX have appeared:

NetRexx — which compiles to Javabyte-code via Java source code; this has no reserved keywords at all, and uses the Java object model, and is therefore not generally upwards-compatible with ‘classic’ REXX.

In 1990, Cathy Dager of SLAC organized the first independent REXX symposium, which led to the forming of the REXX Language Association. Symposia are held annually.

REXX marked its 25th anniversary on 20 March 2004, which was celebrated at the REXX Language Association’s 15th International REXX Symposium in Böblingen, Germany, in May 2004.

On October 12, 2004, IBM announced their plan to release their Object REXX implementation under the Common Public License. Recent releases of Object Rexx contain a ActiveX WSH scripting engine implementing this version of the Rexx language.

On February 22, 2005, the first public release of Open Object Rexx (ooRexx) was announced. This product contains a WSH scripting engine which allows for programming of the Windows operating system and applications with Rexx in the same fashion in which Visual Basic and Java/J++ are implemented by the default WSH installation and Perl, Tcl, Python third-party scripting engines. The default filename extension for ooRexxScript scripts is *.rxs.

A command-line Rexx interpreter is also installed with ooRexx, and it is also possible to run ooRexxScript programmes from the command line by means of the CScript command (WScript may also be run from the command line) invoking the Windows Scripting Host.

A Rexx IDE, RxxxEd, has been developed for Windows. RxSock for network communication as well as other add-ons to and implementations of Regina Rexx have been developed, and a Rexx interpreter for the Windows command line is supplied in most Resource Kits for various versions of Windows and works under all of them as well as MS-DOS.

Portable Rexx by Kilowat and Personal Rexx by Quercus are two Rexx interpreters designed for MS-DOS and can of course be run under Windows as well using a command prompt.

Spelling

Originally it was just called "Rex", "A Reformed EXecutor"; the extra "X" was added to avoid collisions with other products' names. The expansion of Rexx to the REstructured EXtended EXecutor is believed to be a backronym. REX was originally all uppercase because the mainframe code was uppercase oriented. The style in those days was to have all-caps names (partly because almost all code was still all-caps then). For the product it became REXX, and both editions of Mike Cowlishaw's book use all-caps. By the 1990s it was largely written Rexx or, with small caps: REXX. As of 2008, Mike Cowlishaw seems to prefer Rexx, IBM documents use REXX, and the ANSI standard uses REXX.

Syntax

Looping

The loop control structure in REXX begins with a DO and ends with an END but comes in several varieties. NetRexx uses the keyword LOOP instead of DO for looping, while ooRexx treats LOOP and DO as equivalent when looping.

Traditional forms:

dountil [condition]
[instructions]
end

dowhile [condition]
[instructions]
end

With an index variable:

doi = x [toy ][byz]
[instructions]
end

The step increment (z above) may be omitted and defaults to 1. The upper limit (y above) can also be omitted, which makes the loop continue forever. You can also loop forever without an index variable with this:

doforever
[instructions]
end

A program can break out of the current loop with the leave instruction (which is the normal way to exit a "forever" loop), or can short-circuit it with the iterate instruction. The do while and do until forms are equivalent to:

doforeverif [condition] thenleave
[instructions]
end

and:

doforever
[instructions]
if [condition] thenleaveend

Conditionals

Testing conditions with IF

if [condition] thendo
[instructions]
endelsedo
[instructions]
end

For single instructions, DO and END can also be omitted:

if [condition] then
[instruction]
else
[instruction]

Testing for multiple conditions

SELECT is REXX's CASE structure, like many other constructs derived from PL/I:

Compound variables

Unlike many other programming languages, classic REXX has no direct support for arrays of variables addressed by a numerical index. Instead it provides compound variables. A compound variable consists of a stem followed by a tail. A . (dot) is used to join the stem to the tail. If the tails used are numeric, it is easy to produce the same effect as an array.

Unlike arrays, the index for a stem variable is not required to have an integer value. For example, the following code is valid:

i = 'Monday'
stem.i = 2

In REXX it is also possible to set a default value for a stem.

stem. = 'Unknown'
stem.1 = 'USA'
stem.44 = 'UK'
stem.33 = 'France'

After these assignments the term stem.3 would produce 'Unknown'.

The whole stem can also be erased with the DROP statement.

drop stem.

This also has the effect of removing any default value set previously.

By convention (and not as part of the language) the compound stem.0 is often used to keep track of how many items are in a stem, for example a procedure to add a word to a list might be coded like this:

It is also possible to have multiple elements in the tail of a compound variable. For example:

m = 'July'
d = 15
y = 2005
day.y.m.d = 'Friday'

Multiple numerical tail elements can be used to provide the effect of a multi-dimensional array.

Features similar to REXX compound variables are found in many other languages (associative arrays in AWK, hashes in Perl, Hashtables in Java, etc). Most of these languages provide an instruction to iterate over all the keys (or tails in REXX terms) of such a construct, but this is lacking in classic REXX. Instead it is necessary to keep auxiliary lists of tail values as appropriate.
For example in a program to count words the following procedure might be used to record each occurrence of a word.

However, REXX provides no safety net here, so if one of your words happens to be a whole number less than dictionary.0 the above technique will fail mysteriously.

Recent implementations of REXX, including IBM's Object REXX and the open source implementations like ooRexx include a new language construct to simplify iteration over the value of a stem, or over another collection object such as an array, table, list, etc.

do i over stem.
say i '-->' stem.i
end

Keyword instructions

PARSE

The PARSE instruction is particularly powerful; it combines some useful string-handling functions. Its syntax is:

parse [upper] origin template

where origin specifies the source:

arg (arguments, at top level tail of command line)

linein (standard input, e.g. keyboard)

pull (REXX data queue or standard input)

source (info on how program was executed)

value (an expression) with

the keyword with is required to indicate where the expression ends

var (a variable)

version (version/release number)

and template can be:

list of variables

column number delimiters

literal delimiters

upper is optional; if you specify it, data will be converted to upper case.

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

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

SIGNAL

The REXX SIGNAL instruction is intended for abnormal changes in the flow of control (see the next section). However, it can be misused and treated like the GOTO statement found in other languages (although it is not strictly equivalent, because it terminates loops and other constructs). This can produce difficult to read code.

Error handling and exceptions

It is possible in REXX to intercept and deal with errors and other exceptions, using the SIGNAL instruction. There are seven system conditions: ERROR, FAILURE, HALT, NOVALUE, NOTREADY, LOSTDIGITS and SYNTAX. Handling of each can be switched on and off in the source code as desired.

This example will run until stopped by the user:

signal on halt;
do a = 1
say a
do 100000 /* a delay */
endendhalt:
say "The program was stopped by the user"
exit

Virtually all serious REXX programs contain signal on novalue or a similar statement. This disables the "feature", where undefined variables get their own (upper case) name as value. The status of a variable can be checked with the built-in function SYMBOL returning VAR for defined variables.

Function VALUE can be used to get the value of variables without triggering a NOVALUE condition, but its main purpose is to read and set environment variables - similar to POSIXgetenv and putenv.

When a condition is handled by SIGNAL ON, the SIGL and RC system variables can be analyzed to understand the situation. RC contains the REXX error code and SIGL contains the line number where the error arose.

Beginning with REXX version 4 conditions can get names, and there's also a CALL ON construct. That's handy if external functions do not necessarily exist: