This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages) (Learn how and when to remove this message)
|
| Rexx | |
|---|---|
| Paradigm | multiparadigm:procedural,structured |
| Designed by | Mike Cowlishaw |
| Developer | Mike Cowlishaw,IBM |
| First appeared | 1979; 46 years ago (1979) |
| Stable release | |
| Typing discipline | Dynamic |
| Filename extensions | .cmd, .bat, .exec, .rexx, .rex, EXEC |
| Majorimplementations | |
| VM/SP R3,[1] TSO/E V2,[2] SAAREXX,[3][4]ARexx, BREXX, Regina,[5] Personal REXX, REXX/imc | |
| Dialects | |
| NetRexx,Object REXX, nowooREXX,KEXX | |
| Influenced by | |
| PL/I,ALGOL,EXEC,EXEC 2 | |
| Influenced | |
| NetRexx,Object REXX | |
| |
Rexx (restructured extended executor) is ahigh-level programming language developed atIBM byMike Cowlishaw.[6][7] Both proprietary andopen source Rexxinterpreters exist for a wide range ofcomputing platforms, andcompilers exist for IBMmainframe computers.[8] Rexx is used forscripting,applicationmacros andapplication development. As a general purpose scripting language, Rexx is considered a precursor toTcl andPython.
Rexx is supported in a variety of environments. It is the primary scripting language in someoperating systems includingOS/2,MVS,VM,AmigaOS and is used for macros in some software includingSPF/PC,KEDIT,THE andZOC. With an engine installed, Rexx can be used for scripting and macros in programs that use aWindows Scripting HostActiveX scripting engine (such asVBScript orJScript). Rexx is supplied with VM/SP Release 3 on up, TSO/E Version 2 on up, OS/2 (1.3 and later, where it is officially namedProcedures Language/2),AmigaOS Version 2 on up,PC DOS (7.0 or2000),ArcaOS,[9] and Windows NT 4.0 (Resource Kit: Regina). In the late 1980s, Rexx became the common scripting language forIBM Systems Application Architecture, where it was renamed "SAA Procedure Language REXX".
A script is associated with a Rexx interpreter at runtime in various ways based on context. In mainframe computing, a Rexx script or command is sometimes referred to as anEXEC since that is the name of the file type used for similarCMSEXEC,[10] andEXEC 2[11] scripts and for Rexx scripts onVM/SP R3 throughz/VM. The first line of a script specifies the use of a Rexx interpreter in a comment either by identifying the code as Rexx language or by file path viaEXTPROC. On MVS, Rexx scripts may[a] be recognized by the low level qualifier "EXEC" or if the first line fetched from SYSPROC is a comment containing "REXX" then it is treated as Rexx (rather than CLIST), and a script fetched from SYSEXEC must be Rexx. On OS/2, Rexx scripts share the filename extension ".cmd" with other scripting languages, and the first line of the script specifies the interpreter to use. OnLinux, Rexx scripts generally begin with ashebang. Rexx macros for Rexx-aware applications use extensions determined by the application.
Originally, the language was calledREX, short forReformed Executor, but an extra "X" was added to avoid confusion with other products. The name was originally all uppercase because that was the only way to represent it in mainframe code at the time. Both editions of Mike Cowlishaw's first book on the language use all-caps,REXX, although the cover graphic uses mixed case. His book on NetRexx uses mixed case but all caps in the cover graphic with large and small caps,NETREXX. An expansion that matches the abbreviation,REstructured eXtended eXecutor, was used for the system product in 1984.[12] The nameRexx (mixed case) is used in this article, and is commonly used elsewhere.
Objective and subjective attributes of Rexx include:
Some claim that Rexx is a relatively simple language. With only 23 instructions (such ascall,parse, andselect), it has a relatively small instruction set. Rexx has limited punctuation and formatting requirements. Rexx has only onedata type, the character string. Some claim that such simplicities make Rexx relatively easy to debug.
Some claim that Rexx code looks similar toPL/I code, but has fewer notations. With fewer notations, it tends to be is harder to parse via a translator, but is easier to write. Simplifying coding was intentional as noted by the Rexx design goal of theprinciple of least astonishment.[12]
On his own time,Mike Cowlishaw developed the language and an interpreter for it inassembly language between 20 March 1979 and mid-1982 with the intent to replace the languagesEXEC andEXEC 2.[6] Mike also intended Rexx to be a simplified and easier to learn version ofPL/I, but some claim that Rexx has problematic differences from PL/I.
Rexx was first described in public at the SHARE 56 conference in Houston, Texas, in 1981,[13] where customer reaction, championed by Ted Johnston ofSLAC, 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,MVS TSO/E,IBM OS/400,VSE/ESA,MUSIC/SP,AIX,PC DOS, andOS/2), and has made versions available forNovell NetWare,Windows,Java, andLinux.
The first non-IBM version was written forPC DOS by Charles Daney in 1984/5[7] and marketed by the Mansfield Software Group (founded by Kevin J. Kearney in 1986).[6] The first Rexx compiler appeared in 1987, written for CMS by Lundin and Woodruff.[14] Other versions have also been developed forAtari,AmigaOS,Unix (many variants),Solaris,DEC,Windows,Windows CE,Pocket PC,DOS,Palm OS,QNX,OS/2,Linux,BeOS,EPOC32/Symbian,AtheOS,OpenVMS,[15]: 309 AppleMacintosh, andMac OS X.[16]
ARexx, a Rexx interpreter forAmiga, was included with AmigaOS 2 onwards and was popular for scripting and application control. Many Amiga applications have an "ARexx port" which allows control of the application via a Rexx script. Notably, a Rexx script can switch between Rexx ports to control multiple applications.
In 1990, Cathie Dager of SLAC organized the first independent Rexx symposium, which led to the forming of the Rexx Language Association. Symposia are held annually.
In 1992, the two most widely usedopen-source ports appeared: Ian Collier's REXX/imc for Unix and Anders Christensen's Regina[5] (later adopted by Mark Hessling) for Windows and Unix. BRexx was developed by Vasilis N Vlachoudis, a nuclear scientist atCERN. It runs on a range of operating systems, including Unix, Linux, BSD, macOS and Windows. Its small size means it can run on anAndroid mobile phone. BRexx/370 is a version that runs on IBM mainframes.[15]: 359–383 [17]
OS/2 has a visual development system from WatcomVX-REXX. Another dialect was VisPro REXX from Hockware.
Portable Rexx by Kilowatt andPersonal Rexx by Quercus are two Rexx interpreters designed for DOS and can be run under Windows as well using a command prompt. Since the mid-1990s, two newer variants of Rexx have appeared:
In 1996 theAmerican National Standards Institute (ANSI) published a standard for Rexx: ANSI X3.274–1996 "Information Technology – Programming Language REXX".[c] More than two dozen books on Rexx have been published since 1985.
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 theirObject REXX implementation's sources under theCommon Public License. Recent releases of Object REXX contain an ActiveXWindows Scripting Host (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 whichVisual Basic andJScript are implemented by the default WSH installation andPerl,Tcl,Python third-party scripting engines.
In January 2018 theTIOBE index listed Rexx at position 30.[19] Since 2018 it has been either outside the top 50, or, more frequently, outside the top 100.
In 2019, the 30th Rexx Language Association Symposium marked the 40th anniversary of Rexx. The symposium was held in Hursley, England, where Rexx was first designed and implemented.[20]
A Rexx host environment is a named interface for sendingcommands to an, e.g., application, operating system, subsystem. The Rexx interpreter initially has a list of known environments; the first in the list is known as thedefault environment. A Rexx script use theADDRESS statement to change the default environment and may also use it to send a single command to a specific environment without changing the default environment.
This sectioncontainsinstructions or advice. Wikipedia is not a guidebook; please helprewrite such content to be encyclopedic or move it toWikiversity,Wikibooks, orWikivoyage.(December 2012) |
Rexx has three instruction types[24]: 31
symbol=expression, assigns a value to a variable; e.g.count=count+1, would add 1 to value in variable "count".say "Message", would print the word 'Message'."sleep 10" would cause a Unix-like host environment to produce a ten seconds delay.Theaddress instruction has three roles:
address instruction with no operand interchanges the first two host environments; normally this reinstate the previous default environment.address instruction with only an environment moves it to the beginning of the list, making it the default environment.address instruction with an environment and an expression passes the value of the expression as a command to the specified environment.The ANSI standard added options for redirecting the input and output of commands.
The language providesdo groups for two purposes:
if orselect statement as a unit for purposes of flow control.do group may optionally contain repetitor phrases, conditional phrases, or both, with termination whenever any of them is satisfied.Ado group begins withdo and ends withend. A single group may serve both purposes. In the related ooRexx and NetRexx, there is both ado and aloop keyword, with almost identical semantics; they differ in that a simpledo is equivalent todo 1 while a simpleloop is equivalent toloop forever.
An iteration of ado group may be terminated with aniterate statement and the entire group may be terminated with aleave statement.
Although it is valid anywhere, a simple do is specifically useful inside conditional statements:
iffoo=barthendoi=1;j=3endelsedoi=2;j=4end
The language supports testing a condition either before (do while) or after (do until) executing a group of code via syntax:
do while [condition] [instructions]end
do until [condition] [instructions]end
The language permits counted loops, where an expression is computed at the start of the loop and the instructions within the loop are executed that many times:
doexpression [instructions]end
A loop can increment a variable and stop when a limit is reached.
doindex=start [tolimit] [byincrement] [forcount] [instructions]end
The increment value is 1 if theby clause is omitted. The loop continues forever if the limitto clause is omitted, unless terminated earlier by another clause or by aleave statement.
The language supports an unconditional loop viaforever that continues until the loop is terminated or the program is terminated.
do forever [instructions]end
Repetitive elements and conditional phrases can be combined in the same loop;[24]: 50 e.g.:
doi=1whilei<=3;sayi;end
doindex=start [tolimit] [by increment] [forcount] [whilecondition] [instructions]end
doexpression [untilcondition] [instructions]end
The language provides forconditional execution viaif,then andelse for a group delimited bydo andend.
if [condition]thendo [instructions]endelsedo [instructions]end
For a single instruction,do andend can be omitted.
if [condition]then [instruction]else [instruction]
The language providesmultiple condition branching viaselect which derives from theSELECT; form of the PL/ISELECT statement.[d] Like similar constructs in other dynamic languages, Rexx'swhen clauses specify full conditions – not equality tests of a single value for the statement as some languages do. In that, they are more like cascadingif-then-else code than like the C or Javaswitch statement.
selectwhen [condition]then [instruction ornop]when [condition]thendo [instructions ornop]endotherwise [instructions ornop]end
Thenop instruction is required if no action is associated with awhen condition.
Theotherwise clause is optional. If omitted and nowhen conditions are met, then thesyntax condition is raised.
Variables 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:
sayhello/* => HELLO */hello=25sayhello/* => 25 */hello="say 5 + 3"sayhello/* => say 5 + 3 */interprethello/* => 8 */drophellosayhello/* => HELLO */
If nonovalue condition handler is configured, then an undefined variable evaluates to its name, in upper case. The built-in functionSYMBOL returns "VAR" for a defined variable and doesnot triggernovalue even if not defined. TheVALUE function gets the value of a variable without triggering anovalue condition, but its main purpose is to read and setenvironment variables, similar toPOSIXgetenv andputenv.
The language provides thecompound variable construct which supports adding fields (called tails) to a variable (called a stem in this context) to support data structures such as lists, arrays, n-dimensional arrays, sparse or dense arrays, balanced or unbalanced trees and records.
The language does not provide special support for numeric array indexing like many other languages do. Instead, a compound variable with numeric tails produce a similar effect.[25]
The following code defines variablesstem.1 = 9, stem.2 = 8, stem.3 = 7...
doi=1to10stem.i=10-iend
Unlike a typical array, a tail (index) need not identify (be named) an integer value. For example, the following code is valid:
i='Monday'stem.i=2
A default value can be assigned to a stem via. but no tail.
stem.='Unknown'stem.1='USA'stem.44='UK'stem.33='France'
In this casestem.3, for example, evaluates to the default value,'Unknown'.
The whole stem (including any default value) can be erased with thedrop statement.
dropstem.
By convention (not part of the language) the compoundstem.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:procedureexposedictionary.parseargwn=dictionary.0+1dictionary.n=wdictionary.0=nreturn
A stem can have multiple tails. For example:
m='July'd=15y=2005day.y.m.d='Friday'
Multiple numerical tail elements can be used to provide the effect of a multi-dimensional array.
Features similar to the compound variable are found in other languages includingassociative arrays inAWK,hashes inPerl andhash tables inJava, dynamic objects inJavaScript. Most of these languages provide a mechanism to iterate over the keys (tails) of such a construct, but this is lacking in classic Rexx. Instead, it is necessary to store additional information. For example, the following procedure might be used to count each occurrence of a word.
add_word:procedureexposecount.word_listparseargw.count.w=count.w+1/* assume count. has been set to 0 */ifcount.w=1thenword_list=word_listwreturn
and then later:
doi=1towords(word_list)w=word(word_list,i)saywcount.wend
More recent Rexx variants, including Object REXX and ooRexx, provide a construct to iterate over the tails of a stem.
doioverstem.sayi'-->'stem.iend
Theparse instruction provides string-handling via syntax:
parse [upper]origin [template]
Ifupper is included then the input is converted to upper case before parsing.
origin describes the input as one of the following:
arg – arguments, at top level tail of command linelinein – standard input, e.g. keyboardpull – Rexx data queue or standard inputsource – info on how program was executedvalueexpressionwith –with indicates the end of the expressionvar – a variableversion – version/release numbertemplate can be a combination of variables, literal delimiters, and column number delimiters.
Using a list of variables as template:
myVar="John Smith"parsevarmyVarfirstNamelastNamesay"First name is:"firstNamesay"Last name is:"lastName
displays:
First name is: JohnLast name is: Smith
Using column number delimiters:
myVar="(202) 123-1234"parsevarMyVar2AreaCode57SubNumbersay"Area code is:"AreaCodesay"Subscriber number is:"SubNumber
displays:
Area code is: 202Subscriber number is: 123-1234
Theinterpret instruction evaluates its argument as a Rexx statement allowing for evaluation of code formatted at runtime. Uses include passing a function as a parameter, arbitrary precision arithmetic, use of theparse statement with programmatic templates, stemmed arrays, and sparse arrays.[how?] The following example displays 16 and exits.
X='square'interpret'say'X||'(4) ; exit'SQUARE:returnarg(1)**2
TheValour software package relied upon Rexx's interpretive ability to implement anOOP environment.[citation needed] Another use was found in an unreleasedWestinghouse product calledTime Machine that was able to fully recover following an otherwise fatal error.[citation needed]
saydigits()fuzz()form()/* => 9 0 SCIENTIFIC */say999999999+1/* => 1.000000000E+9 */numericdigits10/* only limited by available memory */say999999999+1/* => 1000000000 */say0.9999999999=1/* => 0 (false) */numericfuzz3say0.99999999=1/* => 1 (true) */say0.99999999==1/* => 0 (false) */say100*123456789/* => 1.23456789E+10 */numericformengineeringsay100*123456789/* => 12.34567890E+9 */say53//7/* => 4 (rest of division)*/
Calculation of the value√2:
numericdigits50n=2;r=1doforever/* Newton's method */rr=(n/r+r)/2ifr=rrthenleaver=rrendsay"SqRt"n"="r
Output:SqRt 2 = 1.414213562373095048801688724209698078569671875377
Calculation of the valuee:
numericdigits50e=2.5;f=0.5don=3f=f/nee=e+fife=eethenleavee=eeendsay"e ="e
Output:e = 2.7182818284590452353602874713526624977572470936998
Thesignal instruction configures the runtime to run custom code to handle a system condition if triggered. Conditions include:
error – Positive return code from a system commandfailure – Negative return code from a system command (e.g. command doesn't exist)halt – Abnormal terminationnovalue – A variable name was used but the variable is not definednotready – Input or output error (e.g. read attempts beyond end of file)syntax – Invalid program syntax, or some other error conditionlostdigits – Significant digits were lost (ANSI Rexx, not in TRL second edition)The following fragment prints a message when the user terminates (halts) it:
signalonhalt;doa=1sayado100000/* a delay */endendhalt:say"The program was stopped by the user"exit
Since Rexx version 4, a handler can be named. In the following example, the handlerChangeCodePage.Trap is configured to handle asyntax condition.
ChangeCodePage:proceduresignalonsyntaxnameChangeCodePage.TrapreturnSysQueryProcessCodePage()ChangeCodePage.Trap:return1004
When a condition is handled (as configured viasignal on), the condition can be analyzed viaRC which indicates the last error code andSIGL which indicates the line number of the code that triggered the condition.
SELECT (expression); form.Could there be a high astonishment factor associated with the new feature? If a feature is accidentally misapplied by the user and causes what appears to him to be an unpredictable result, that feature has a high astonishment factor and is therefore undesirable. If a necessary feature has a high astonishment factor, it may be necessary to redesign the feature.