REXX is an
interpretedInterpreted language is a programming language in which programs are 'indirectly' executed by an interpreter program. This can be contrasted with a compiled language which is converted into machine code and then 'directly' executed by the host CPU...
programming languageA programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
that was developed at
IBMInternational Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
. It is a structured
high-level programming languageA high-level programming language is a programming language with strong abstraction from the details of the computer. In comparison to low-level programming languages, it may use natural language elements, be easier to use, or be from the specification of the program, making the process of...
that was designed to be both easy to learn and easy to read. Both proprietary and
open sourceThe term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
interpretersIn computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...
for REXX are available on a wide range of computing platforms, and compilers are available for IBM mainframes.
Rexx is widely used as a
glue languageA glue language is a programming language used for connecting software components together.Examples of glue languages:* Unix Shell scripts * Windows NT type Shell scripts...
, macro language, and is often used for processing data and text and generating reports; these similarities with
PerlPerl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
mean that Rexx works well in
Common Gateway InterfaceThe Common Gateway Interface is a standard method for web servers software to delegate the generation of web pages to executable files...
(CGI) programming and it is indeed used for this purpose. Rexx is the primary scripting language in some operating systems, e.g.
OS/2OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
,
MVSMultiple Virtual Storage, more commonly called MVS, was the most commonly used operating system on the System/370 and System/390 IBM mainframe computers...
,
VMVM refers to a family of IBM virtual machine operating systems used on IBM mainframes System/370, System/390, zSeries, System z and compatible systems, including the Hercules emulator for personal computers. The first version, released in 1972, was VM/370, or officially Virtual Machine Facility/370...
,
AmigaOSAmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...
, and is also used as an internal macro language in some other software, e.g., KEDIT,
THEThe Hessling Editor is one of the older open source text editor projects...
, the ZOC terminal emulator. Additionally, the Rexx language can be used for scripting and macros in any program that 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 VM/SP on up, TSO/E Version 2 on up, OS/2 (1.3 on up), AmigaOS Version 2 on up, PC DOS (7.0 or 2000), and Windows NT 4.0 (Resource Kit: Regina). REXX scripts for OS/2 and NT-based Windows have the filename extension .cmd and the first line of the script determines the operating system the script is for.
Features
REXX has the following characteristics and features:
- simple syntax
- small instruction set containing just two dozen instructions
- freeform
In computer programming, a free-form language is a programming language in which the positioning of characters on the page in program text is not significant. Program text does not need to be placed in specific columns as on old punched card systems, and frequently ends of lines are not significant...
syntax
- case insensitive tokens, including variable names
- character string basis
- dynamic data typing, no declarations
- no reserved keyword
Reserved words are one type of grammatical construct in programming languages. These words have special meaning within the language and are predefined in the language’s formal specifications...
s, except in local context
- arbitrary numerical precision
In computer science, arbitrary-precision arithmetic indicates that calculations are performed on numbers whose digits of precision are limited only by the available memory of the host system. This contrasts with the faster fixed-precision arithmetic found in most ALU hardware, which typically...
- decimal arithmetic, floating-point
- a rich selection of built-in functions, especially string and word processing
- automatic storage management
- crash protection
- content addressable data structures
- associative array
In computer science, an associative array is an abstract data type composed of a collection of pairs, such that each possible key appears at most once in the collection....
s
- straightforward access to system commands and facilities
- simple error-handling, and built-in tracing and debugger
- few artificial limitations
- simplified I/O facilities
- unconventional operators
- only partly supports Unix style command line parameters, except specific implementations
- provides no basic terminal control as part of the language, except specific implementations
- provides no 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 languageIn computer programming, a free-form language is a programming language in which the positioning of characters on the page in program text is not significant. Program text does not need to be placed in specific columns as on old punched card systems, and frequently ends of lines are not significant...
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/IPL/I is a procedural, imperative computer programming language designed for scientific, engineering, business and systems programming applications...
, but has fewer notations; this makes it harder to parse (by program) but easier to use, except for cases where PL/I habits may lead to surprises.
History
REXX was designed and first implemented, in
assembly languageAn assembly language is a low-level programming language for computers, microprocessors, microcontrollers, and other programmable devices. It implements a symbolic representation of the machine codes and other constants needed to program a given CPU architecture...
, as an ‘own-time’ project between 20 March 1979 and mid-1982 by
Mike CowlishawMike Cowlishaw is a retired IBM Fellow, a Visiting Professor at the Department of Computer Science at the University of Warwick, and is a Fellow of the Royal Academy of Engineering , the Institute of Engineering and Technology , and the British Computer Society.- Career at IBM :Cowlishaw joined IBM...
of IBM, originally as a scripting programming language to replace the languages
EXECExec may refer to:* Exec, short for "executive officer"* exec , an operating system function for running a program* Exec , the OS kernel of Amiga computers...
and
EXEC 2EXEC 2 is an interpreted, command procedure control, computer programming language used by the EXEC 2 Processor supplied with the IBM Virtual Machine/Conversational Monitor System operating system....
. It was designed to be a macro or scripting language for any system. As such, REXX is considered a precursor to
TclTcl is a scripting language created by John Ousterhout. Originally "born out of frustration", according to the author, with programmers devising their own languages intended to be embedded into applications, Tcl gained acceptance on its own...
and
PythonPython is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
. REXX was also intended by its creator to be a simplified and easier to learn version of the
PL/IPL/I is a procedural, imperative computer programming language designed for scientific, engineering, business and systems programming applications...
programming language. However, some differences from PL/I may trip up the unwary.
It was first described in public at the SHARE 56 conference in Houston, Texas, in 1981, where customer reaction, championed by Ted Johnston of SLAC, led to it being shipped as an IBM product in 1982.
Over the years IBM included REXX in almost all of its operating systems (VM/CMS, VM/GCS,
MVS TSO/EMultiple Virtual Storage, more commonly called MVS, was the most commonly used operating system on the System/370 and System/390 IBM mainframe computers...
,
AS/400The IBM System i is IBM's previous generation of midrange computer systems for IBM i users, and was subsequently replaced by the IBM Power Systems in April 2008....
, VSE/ESA, AIX, CICS/ESA, PC DOS, and
OS/2OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
), and has made versions available for
Novell NetWareNetWare is a network operating system developed by Novell, Inc. It initially used cooperative multitasking to run various services on a personal computer, with network protocols based on the archetypal Xerox Network Systems stack....
,
WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
,
JavaJava is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
, and
LinuxLinux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
.
The first non-IBM version was written for PC DOS by Charles Daney in 1984/5. The first compiler version appeared in 1987, written for CMS by Lundin and Woodruff. Other versions have also been developed for
AtariAtari is a corporate and brand name owned by several entities since its inception in 1972. It is currently owned by Atari Interactive, a wholly owned subsidiary of the French publisher Atari, SA . The original Atari, Inc. was founded in 1972 by Nolan Bushnell and Ted Dabney. It was a pioneer in...
,
AmigaOSAmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...
,
UnixUnix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...
(many variants), Solaris,
DECDigital Equipment Corporation was a major American company in the computer industry and a leading vendor of computer systems, software and peripherals from the 1960s to the 1990s...
,
WindowsMicrosoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
,
Windows CEMicrosoft Windows CE is an operating system developed by Microsoft for embedded systems. Windows CE is a distinct operating system and kernel, rather than a trimmed-down version of desktop Windows...
,
Pocket PCA Pocket PC is also known by Microsoft as a 'Windows Mobile Classic device'. It is a hardware specification for a handheld-sized computer, personal digital assistant , that runs the Microsoft 'Windows Mobile Classic' operating system...
,
DOSDOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...
,
Palm OSPalm OS is a mobile operating system initially developed by Palm, Inc., for personal digital assistants in 1996. Palm OS is designed for ease of use with a touchscreen-based graphical user interface. It is provided with a suite of basic applications for personal information management...
,
QNXQNX is a commercial Unix-like real-time operating system, aimed primarily at the embedded systems market. The product was originally developed by Canadian company, QNX Software Systems, which was later acquired by Canadian BlackBerry-producer Research In Motion.-Description:As a microkernel-based...
,
OS/2OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
,
LinuxLinux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
,
BeOSBeOS is an operating system for personal computers which began development by Be Inc. in 1991. It was first written to run on BeBox hardware. BeOS was optimized for digital media work and was written to take advantage of modern hardware facilities such as symmetric multiprocessing by utilizing...
, EPOC32,
AtheOSAtheOS was a free and open source operating system for x86-based computers. It was initially intended as an AmigaOS clone, but that objective was later abandoned...
,
OpenVMSOpenVMS , previously known as VAX-11/VMS, VAX/VMS or VMS, is a computer server operating system that runs on VAX, Alpha and Itanium-based families of computers. Contrary to what its name suggests, OpenVMS is not open source software; however, the source listings are available for purchase...
, OpenEdition, Apple
MacintoshThe Macintosh , or Mac, is a series of several lines of personal computers designed, developed, and marketed by Apple Inc. The first Macintosh was introduced by Apple's then-chairman Steve Jobs on January 24, 1984; it was the first commercially successful personal computer to feature a mouse and a...
, and
Mac OS XMac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...
.
The
AmigaThe Amiga is a family of personal computers that was sold by Commodore in the 1980s and 1990s. The first model was launched in 1985 as a high-end home computer and became popular for its graphical, audio and multi-tasking abilities...
version of REXX, called
ARexxARexx is an implementation of the REXX language for the Amiga, written in 1987 by William S. Hawes, with a number of Amiga-specific features beyond standard REXX facilities. Like most REXX implementations, ARexx is an interpreted language...
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
freewareFreeware is computer software that is available for use at no cost or for an optional fee, but usually with one or more restricted usage rights. Freeware is in contrast to commercial software, which is typically sold for profit, but might be distributed for a business or commercial purpose in the...
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 Pocket PC platforms.
OS/2 had a visual development system from Watcom
VX-REXXVX-REXX is a highly-extensible REXX GUI development system for OS/2.Much of the new code in eComStation has been written using VX-REXX.Though REXX is itself a 3GL, the VX-REXX interface allows you to build REXX programs using a combination of 3GL and 4GL techniques; its drag-and-drop interface to...
another dialect was VisPro REXX from Hockware.
In 1996
American National Standards InstituteThe American National Standards Institute is a private non-profit organization that oversees the development of voluntary consensus standards for products, services, processes, systems, and personnel in the United States. The organization also coordinates U.S. standards with international...
(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
NetRexx is an open source, originally IBM's, variant of the REXX programming language to run on the Java virtual machine. It supports a classic REXX syntax, with no reserved keywords, along with considerable additions to support object-oriented programming in a manner compatible with Java's object...
– which compiles to JavaJava is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
byte-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.
- Object REXX
The Object REXX programming language is an object-oriented scripting language initially produced by IBM for OS/2. It is a follow-on to and a significant extension of the "Classic Rexx" language originally created for the CMS component of VM/SP and later ported to MVS, OS/2 and PC DOS.On October 12,...
– which is an object-oriented generally upwards-compatible version of 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 REXXThe Object REXX programming language is an object-oriented scripting language initially produced by IBM for OS/2. It is a follow-on to and a significant extension of the "Classic Rexx" language originally created for the CMS component of VM/SP and later ported to MVS, OS/2 and PC DOS.On October 12,...
implementation's sources under the
Common Public LicenseIn computing, the CPL is a free software / open-source software license published by IBM. The Free Software Foundation and Open Source Initiative have approved the license terms of the CPL....
. 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 BasicVisual Basic is the third-generation event-driven programming language and integrated development environment from Microsoft for its COM programming model...
and
JavaJava is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
/J++ are implemented by the default WSH installation and
PerlPerl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
,
TclTcl is a scripting language created by John Ousterhout. Originally "born out of frustration", according to the author, with programmers devising their own languages intended to be embedded into applications, Tcl gained acceptance on its own...
,
PythonPython is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
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 programs 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 Kilowatt 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 and capitalization
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 E
Xtended E
Xecutor is believed to be a
backronymA backronym or bacronym is a phrase constructed purposely, such that an acronym can be formed to a specific desired word. Backronyms may be invented with serious or humorous intent, or may be a type of false or folk etymology....
. 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: R
EXX. As of 2008, Mike Cowlishaw seems to prefer Rexx, IBM documents use REXX, and the ANSI standard uses R
EXX.
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:
do expression [count]
[instructions]
end
do until [condition]
[instructions]
end
do while [condition]
[instructions]
end
With an index variable:
do i = x [to y] [by z]
[instructions]
end
another variant:
do i = x [by z ] [to y] [for k]
[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:
do forever
[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:
do forever
if [condition] then leave /*similar to WHILE*/
[instructions]
end
and:
do forever
[instructions]
if [condition] then leave /*similar to UNTIL*/
end
Conditionals
Testing conditions with
IF
if [condition] then
do
[instructions]
end
else
do
[instructions]
end
Note that the ELSE clause is optional.
Or, to put it more concisely:
if [condition] then do
[instructions]
end
else do
[instructions]
end
For single instructions,
DO and
END can also be omitted:
if [condition] then
[instruction]
else
[instruction]
Or, in another concise version:
if [condition] then [instruction]
else [instruction]
Indentation is optional, but it helps improve the readability.
Testing for multiple conditions
SELECT is REXX's CASE structure, like many other constructs derived from
PL/IPL/I is a procedural, imperative computer programming language designed for scientific, engineering, business and systems programming applications...
:
select
when [condition] then
[instruction]
when [condition] then
do
[instructions]
end
otherwise
[instructions] or NOP
end
NOP indicates no instruction is to be executed.
Note that the OTHERWISE clause is optional. If omitted and no WHEN conditions are met, then the SYNTAX condition is raised.
Simple variables
Variables in REXX are typeless, and initially are evaluated as their names, in upper case. Thus a variable's
type can vary with its use in the program:
say hello /* => HELLO */
hello = 25
say hello /* => 25 */
hello = "say 5 + 3"
say hello /* => say 5 + 3 */
interpret hello /* => 8 */
drop hello
say hello /* => HELLO */
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.
do i = 1 to 10
stem.i = 10 - i
end
Afterwards the following variables with the following values exist: stem.1 = 9, stem.2 = 8, stem.3 = 7...
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:
add_word: procedure expose dictionary.
parse arg w
n = dictionary.0 + 1
dictionary.n = w
dictionary.0 = n
return
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 arrayIn computer science, an associative array is an abstract data type composed of a collection of pairs, such that each possible key appears at most once in the collection....
s in AWK,
hashesIn computer science, a hash table or hash map is a data structure that uses a hash function to map identifying values, known as keys , to their associated values . Thus, a hash table implements an associative array...
in
PerlPerl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...
,
Hashtables in
JavaJava is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
,
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.
add_word: procedure expose count. word_list
parse arg w .
count.w = count.w + 1 /* assume count. has been set to 0 */
if count.w = 1 then word_list = word_list w
return
and then later
do i = 1 to words(word_list)
w = word(word_list,i)
say w count.w
end
At the cost of some clarity it is possible to combine these techniques into a single stem.
add_word: procedure expose dictionary.
parse arg w .
dictionary.w = dictionary.w + 1
if dictionary.w = 1 /* assume dictionary. = 0 */
then do
n = dictionary.0+1
dictionary.n = w
dictionary.0 = n
end
return
and later
do i = 1 to dictionary.0
w = dictionary.i
say i w dictionary.w
end
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
IBMInternational Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
's Object REXX and the open source implementations like ooRexx include a new
language constructA language construct is a syntactically allowable part of a program that may be formed from one or more lexical tokens in accordance with the rules of a programming language....
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
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 specified, data will be converted to upper case before parsing.
Examples:
Using a list of variables as template
myVar = "John Smith"
parse var myVar firstName lastName
say "First name is:" firstName
say "Last name is:" lastName
displays the following:
First name is: John
Last name is: Smith
Using a delimiter as template:
myVar = "Smith, John"
parse var myVar LastName "," FirstName
say "First name is:" firstName
say "Last name is:" lastName
also displays the following:
First name is: John
Last name is: Smith
Using column number delimiters:
myVar = "(202) 123-1234"
parse var MyVar 2 AreaCode 5 7 SubNumber
say "Area code is:" AreaCode
say "Subscriber number is:" SubNumber
displays the following:
Area code is: 202
Subscriber number is: 123-1234
A template can use a combination of variables, literal delimiters, and column number delimiters.
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- The product :Valour, also called DiskWorks as well as strategic marketing brands chosen by vendors, grew out of a plan to rewrite the aging Westinghouse Disc Utility and target the full range of IBM operating systems....
package relied upon REXX's interpretive ability to implement an
OOPObject-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...
environment. Another use was found in an unreleased
WestinghouseWestinghouse may refer to:In current companies:*Westinghouse Licensing, the brand management division of CBS Corporation, and its licensees:**Westinghouse Electric Company LLC, providing nuclear power related services....
product called
Time Machine that was able to fully recover following a fatal error.
NUMERIC
say digits fuzz form /* => 9 0 SCIENTIFIC */
say 999999999+1 /* => 1.000000000E+9 */
numeric digits 10 /* only limited by available memory */
say 999999999+1 /* => 1000000000 */
say 0.9999999999=1 /* => 0 (false) */
numeric fuzz 3
say 0.99999999=1 /* => 1 (true) */
say 0.999999991 /* => 0 (false) */
say 100*123456789 /* => 1.23456789E+10 */
numeric form engineering
say 100*123456789 /* => 12.34567890E+9 */
numeric digits 50
n=2
r=1
do forever /* Newton's method */
rr=(n/r+r)/2
if r=rr then leave
r=rr
end
say "root" n '=' r /*root 2=1.414213562373095048801688724209698078569671875377*/
numeric digits 50
e=2.5
f=0.5
do n=3
f=f/n
ee=e+f
if e=ee then leave
e=ee
end
say "e=" e /*e=2.7182818284590452353602874713526624977572470936998*/
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
GOTOgoto is a statement found in many computer programming languages. It is a combination of the English words go and to. It performs a one-way transfer of control to another line of code; in contrast a function call normally returns control...
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:
On most PCs, halting would be accomplished by pressing the Ctrl-Pause (also called the Break key).
On some mainframe systems, pressing the PA1 key (Program Assist).
signal on halt;
do a = 1
say a
do 100000 /* a delay */
end
end
halt:
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
POSIXPOSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...
getenv and
putenv.
Conditions
| ERROR |
Positive RC from a system command |
| FAILURE |
Negative RC for a system command (e.g. command doesn't exist) |
| HALT |
Abnormal termination (see above) |
| NOVALUE |
An unset variable was referenced (see above) |
| NOTREADY |
Input or output error (e.g. read attempts beyond end of file) |
| SYNTAX |
Invalid program syntax, or some error condition not covered above |
| LOSTDIGITS |
Significant digits are lost (ANSI REXX, not in TRL second edition) |
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:
ChangeCodePage: procedure /* protect SIGNAL settings */
signal on syntax name ChangeCodePage.Trap
return SysQueryProcessCodePage
ChangeCodePage.Trap: return 1004 /* windows-1252 on OS/2 */
See also
- ARexx
ARexx is an implementation of the REXX language for the Amiga, written in 1987 by William S. Hawes, with a number of Amiga-specific features beyond standard REXX facilities. Like most REXX implementations, ARexx is an interpreted language...
, the native REXX interpreter of AmigaOSAmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...
- ISPF
In computing, Interactive System Productivity Facility is a software product for the z/OS operating system that runs on IBM mainframes...
, dialog manager and text editor(s) with native REXX support
- XEDIT
XEDIT is a visual editor for VM/CMS using block mode IBM 3270 terminals.It is much more line-oriented than modern PC and Unix editors. For example, it supports automatic line numbers, and many of the commands operate on blocks of lines. One of the features is a command line which allows the user to...
, text editor(s) with native REXX support
- NetRexx
NetRexx is an open source, originally IBM's, variant of the REXX programming language to run on the Java virtual machine. It supports a classic REXX syntax, with no reserved keywords, along with considerable additions to support object-oriented programming in a manner compatible with Java's object...
, a Rexx-like language compiling into Java byte code
- Object REXX
The Object REXX programming language is an object-oriented scripting language initially produced by IBM for OS/2. It is a follow-on to and a significant extension of the "Classic Rexx" language originally created for the CMS component of VM/SP and later ported to MVS, OS/2 and PC DOS.On October 12,...
, an object-oriented programming languageThis is a list of object-oriented programming programming languages.-Languages with object-oriented features:*ABAP*Ada 95*AmigaE*BETA*Blue*Boo*C++*C#*COBOL*Cobra*ColdFusion*Common Lisp*COOL*CorbaScript*Clarion*CLU*Curl*D*Dylan*E*Eiffel...
based on the REXX language
- Comparison of computer shells
A command shell is a command line interface computer program to an operating system.- General characteristics :- Interactive features :- Programming features :- Syntax :- Data types :- String and filename matching :...
- Comparison of programming languages
Programming languages are used for controlling the behavior of a machine . Like natural languages, programming languages conform to rules for syntax and semantics.There are thousands of programming languages and new ones are created every year...
Books
- Callaway, Merrill. The Rexx Cookbook: A Tutorial Guide to the Rexx Language in OS/2 & Warp on the IBM Personal Computer. Whitestone, 1995. ISBN 0-96-327734-0.
- Cowlishaw, Michael. The Rexx Language: A Practical Approach to Programming. Prentice Hall, 1990. ISBN 0-13-780651-5.
- Cowlishaw, Michael. The NetRexx Language. Prentice Hall, 1997. ISBN 0-13-806332-X.
- Daney, Charles. Programming in REXX. McGraw-Hill, TX, 1990. ISBN 0-07-015305-1.
- Deuring, Johannes. REXX Grundlagen für die z/OS Praxis. Germany, 2005. ISBN 3-486-20025-9.
- Ender, Tom. Object-Oriented Programming With Rexx. John Wiley & Sons, 1997. ISBN 0-471-11844-3.
- Fosdick, Howard. Rexx Programmer's Reference. Wiley/Wrox, 2005. ISBN 0-7645-7996-7.
- Gargiulo, Gabriel. REXX with OS/2, TSO, & CMS Features. MVS Training, 1999 (third edition 2004). ISBN 1-892559-03-X.
- Goldberg, Gabriel and Smith, Philip H. The Rexx Handbook . McGraw-Hill, TX, 1992. ISBN 0-07-023682-8.
- Goran, Richard K. REXX Reference Summary Handbook. CFS Nevada, Inc.,1997. ISBN 0-9639854-3-4.
- IBM Redbooks. Implementing Rexx Support in Sdsf. Vervante, 2007. ISBN 0-738-48914-X.
- Kiesel, Peter C. Rexx: Advanced Techniques for Programmers. McGraw-Hill, TX, 1992. ISBN 0-07-034600-3.
- Marco, Lou ISPF/REXX Development for Experienced Programmers. CBM Books, 1995. ISBN 1-878956-50-7
- O'Hara, Robert P. and Gomberg, David Roos. Modern Programming Using Rexx. Prentice Hall, 1988. ISBN 0-13-597329-5.
- Rudd, Anthony S. Practical Usage of Rexx. Ellis Horwood Ltd., 1991. ISBN 0-13682-790-X.
- Schindler, William. Down to Earth Rexx. Perfect Niche Software, 2000. ISBN 0-9677590-0-5.
External links
Classic interpreters
- Regina: open-source (LGPL) interpreter for Linux, BSD, Windows, etc.
- REXX/imc: source available (non-standard license) interpreter for Unix and Linux systems.
- BREXX: source available (non-commercial) interpreter for Linux, DOS, Windows CE, etc.. (Versions 2.1.3 to 2.1.6 are available under GPL licence (see file COPYING in unpacked tarball.))
- Reginald: free interpreter for Windows.
- roo!: freeware interpreter for Windows with object-oriented extensions from Kilowatt Software.
- r4: freeware interpreter for Windows from Kilowatt Software.
- S/REXX: commercial interpreter for UNIX and Windows from Benaroya.
- uni-REXX: commercial interpreter for UNIX from The Workstation Group Ltd.
Other interpreters
Compilers
Software using REXX for scripting
- OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
- z/OS
z/OS is a 64-bit operating system for mainframe computers, produced by IBM. It derives from and is the successor to OS/390, which in turn followed a string of MVS versions.Starting with earliest:*OS/VS2 Release 2 through Release 3.8...
- z/VM
z/VM is the current version in IBM's VM family of virtual machine operating systems. z/VM was first released in October 2000 and remains in active use and development . It is directly based on technology and concepts dating back to the 1960s, with IBM's CP/CMS on the IBM System/360-67...
- ISPF and XEDIT clones
- AmigaOS
AmigaOS is the default native operating system of the Amiga personal computer. It was developed first by Commodore International, and initially introduced in 1985 with the Amiga 1000...
, MorphOSMorphOS is an Amiga-compatible computer operating system. It is a mixed proprietary and open source OS produced for the Pegasos PowerPC processor based computer, PowerUP accelerator equipped Amiga computers, and a series of Freescale development boards that use the Genesi firmware, including the...
, AROSAros may refer to:*Aros , a river in J. R. R. Tolkien's Middle-earth legendarium*AROS Research Operating System, a free software implementation of AmigaOS* Aros, the original Viking name of Aarhus, the second largest city in Denmark...
Tutorials
- Rexx for everyone: An introduction by David Mertz for IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
developerWorksdeveloperWorks is a free web-based professional network and technical resource center from IBM for software developers, IT professionals, and students worldwide...
.
- Vladimir Zabrodsky's Album of Algorithms and Techniques for Standard Rexx
- Vladimir Zabrodsky's An Introduction to the Rexx Programming Language
- PLEAC-REXX: Programming Language Examples Alike Cookbook for REXX
- Tips & tricks 3.60 by Bernd Schemmer (OS/2 INF format, 755 KB ZIP, 2004)
- Rexx Frequently Asked Questions (FAQ)
- Introductory Rexx Tutorial, SHARE, Spring 1997