Rexx

From Citizendium
Jump to navigation Jump to search
This article is a stub and thus not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
 
This editable Main Article is under development and subject to a disclaimer.

Rexx (REstructured eXtended eXecutor) is a high-level computer programming language developed between 1979 and 1982 by M. F. Cowlishaw. Although Cowlishaw, who is an IBM employee, developed the language in his spare time, IBM soon recognized the usefulness of the language and introduced it in 1982 into the operating system VM/CMS as its main scripting language. Around the same time IBM's CMS editor, XEDIT, was extended so that edit macros could be written in Rexx.

At present IBM includes support for the language in almost all its operating systems. Non-IBM freeware versions are available for Microsoft Windows, most variants of Unix, and Mac OS X.

Features of the language are: easy to learn, procedural, interpreted, untyped (or rather one type: character string of arbitrary length), support of numbers of arbitrary precision, associative arrays, powerful character string parsing, invokable from different environments, passing commands to its invoking environments.

There are text editors, notably IBM's XEDIT[1], Mansfield's KEDIT[2], and Hessling's THE[3], that are integrated with Rexx. Such integrated pairs form a powerful tool: from the editor a Rexx macro may be invoked and from the Rexx macro editor statements may be issued. This feature allows an almost infinite extension and adaptation of a text editor to one's personal needs. Word processors, such as Word® and WordPerfect®, are usually to be preferred for natural language texts—except for texts typeset by markup languages like HTML and LaTeX—but for editing of computer programs and many kinds of data files, text editors (plus programmable extensions like Rexx) are a very good option.

Sample macro

To give the flavor of Rexx, a sample editor macro is presented. It is assumed that the editor acts on a data file consisting of lines. The data file is assumed sorted so that duplicate lines are consecutive. The macro finds the duplicate lines and deletes them. The macro is invoked from the editor command line with two numeric arguments, col1 and col2, which means that only the character string between columns col1 and col2 is checked for duplication.

 parse arg LeftCol RightCol  /* parse arguments (column numbers)*/

 if LeftCol = "" & RightCol = "" then do /* No column numbers */
    /* Use default columns */
    LeftCol = 1
    RightCol = 80
    end
 if datatype(LeftCol) \= "NUM" | datatype(RightCol) \= "NUM" then do
 /* (Rexx has function datatype, returns "NUM" or "CHAR") */

    'emsg  Error 1: Invalid columns specified "'LeftCol RightCol'"'
 /* (Command between quotes is passed back to calling environment, */
 /*  "emsg" is editor command [error message])                     */
    exit 1  /* Leave macro plus error code */
    end

 if RightCol > width.1() then do  /* width is editor function */
    RightCol = width.1()
    say "Specified right column > WIDTH setting... adjusted to" RightCol
    end

 if LeftCol > RightCol then do
    'emsg  Error 2: Specified left column > right column "'LeftCol RightCol'"'
    exit 1
    end

 "preserve"          /* Save all editor settings, such as automatic save */
 "autosave off"
 "top"               /* Editor command: top of file */
 NumDups = 0

 /* Loop to process all lines of the file */
 do forever
    CompareLine = substr(curline.3(), LeftCol, RightCol-LeftCol+1)
 /* curline is editor function, returns current line; substr is Rexx function */
    "down 1"        /* Editor command; next line */

    /* Loop to delete all duplicates of one particular line */
    do forever
       /* Have we hit the end of the file? */
       if focuseof() then leave  /* Editor function */

       /* Is this a duplicate? */
       if CompareLine \== substr(curline.3(), LeftCol, RightCol-LeftCol+1) then leave
       "delete 1"  /* Editor command, delete one line */
       NumDups = NumDups + 1 /* Count number of duplicates */
       end

    if focuseof() then leave /* If current line end-of-file, leave loop */
    end

 "top"
 "restore"  /* All editor settings restored */
 say NumDups "duplicate lines have been deleted..."
 exit 0

References

  1. XEDIT User's Guide. (2d ed., Dec. 2005, pub. no. SC24-6132-01). International Business Machines
  2. KEDIT (commercial)
  3. THE (freeware)

External link