[ Go back to normal view ]

BW2 :: the bitwise supplement :: http://www.bitwisemag.com/2

Rexx World
Power plus simplicity - is Rexx the programming language you’ve been searching for?

8 January 2007

by Howard Fosdick

There are millions of free and open source languages, tools, and development accessories out there. How do you find the right ones for your work?

I’d like to introduce you to a world of related languages and tools with which you may not be familiar. All relate to Rexx, a free scripting language used worldwide, that offers 9 free interpreters and thousands of add-on tools that run on every platform, from handheld devices to mainframes (and everything in-between). This brief article tells you everything you need to know—



The defining characteristic of Rexx is that it combines ease of use with power. This is a neat trick – normally these traits conflict. How does Rexx pull it off? Rexx has—

- Minimal syntax
- Consistent, reliable behavior based on a minimum of rules
- Features are based on linguistic flexibility — rather than identifying syntax
- A small instruction set with functions and objects providing power
- Extensibility
- Free format
- Strong language standards

I do most my scripting in either Perl, the Korn shell, or Rexx. Each has its own unique personality and advantages.

I choose Korn when I need a standard shell language for coding on Unix systems in IT shops. I like Perl for the unparalleled size of its free code library, its power, and its portability.

I pick Rexx when I want a language that I can—

- Code from memory, without looking up complicated syntax
- Know will produce code that can be maintained
- Ensure my programs outlive my presence at the client
- Develop large systems with quickly – with a minimum of errors

This last point bears amplification. When I tell high-end developers that Rexx is powerful yet easy, they sometimes recoil in horror – why would a top-notch developer ever use an easy language? (What an insult!)

Here’s why – you can write a ton of code very quickly. You are freed from the shackles of syntax, so this code requires minimal debugging. And here’s the coup de grace – this code will be highly reliable.

If you consider yourself a “real” coder, writing large commercial systems, there’s much to be said for the so-called easy languages like Rexx. You can write big complex systems, fast and reliably, and this code can be understood and maintained by those who follow in your footsteps.

Varieties of Rexx

Like many languages, Rexx started life as a procedural language. Traditional or classic Rexx today runs on every platform, from handheld devices, to PCs, servers, and mainframes. Six classic free interpreters are available. All conform to the Rexx standards, which are strong and guarantee portability.

The availability of different interpreters means you can choose which is most appropriate to your task – the fastest one, the one tweaked and extended for Windows, the one bundled with your favorite tools, the one with the smallest footprint, or whatever. This presents a big advantage compared to scripting languages that offer only a single source. Choice is good! But like all benefits, this one comes with a cost — not every one of the thousands of free Rexx tools interfaces with every interpreter.

Beyond classic procedural Rexx, there are two fully object-oriented versions of the language. Open Object Rexx was originally developed at IBM. It was open-sourced in December 2004 and handed over to the Rexx Language Association for support and further development. Often called ooRexx, this interpreter is a huge hit. In 2006 it ranked among the top 5 % of all downloads on SourceForge.

ooRexx has the full set of features you would expect in a good object-oriented interpreter - single and multiple inheritance, operator overloading and polymorphism, data encapsulation, messaging, classes, objects, and a huge hammer of a class library. Take a look at the class library in this reference card (pdf).

The other free object-oriented Rexx is roo!. roo! is also fully object-oriented but features completely different OO syntax and classes. I’ve found it particular useful in education, based on its friendly, fun documentation and free tutorial.

Both ooRexx and roo! are true supersets of classic Rexx. Any procedural Rexx program runs under either without alteration. This is a big benefit for sites upgrading procedural code to object-oriented, and for individual programmers who are learning OO programming (just code procedural Rexx and add object-oriented features at the rate at which you feel comfortable).

As I write this column, ooRexx’s SourceForge Activity Rating is 99.53% and its Download Rank is 835. Quite an accomplishment on a site that features 137,389 projects. SourceForge downloads statistics prove that basing a quality object-oriented interpreter like ooRexx on top of the strong procedural Rexx standard is a winner.

A Sample Program

Let’s take a look at a procedural Rexx program. We won’t stray into tools, IDE’s, GUIs, interpreter choices or the like… we’ll just stick to the basics – the code.

This program scans input text and analyzes its complexity by calculating ratios between longer words and shorter ones, and between prepositions and non-prepositions.

While this program is quite simple, text-scanning has proven useful in such diverse tasks as identifying the authorship of manuscripts and analyzing writing styles. An academic even used a text-scanner to predict the winner of the 2004 U.S. presidential election based on the reasoning styles embodied in the candidates’ speeches.

Here is our simple text scanner. It performs some fundamental poetry analysis—

/*  POETRY SCANNER:                                                  */
/*                                                                   */
/*     This program scans text to perform primitive text analysis.   */

list_of_articles = 'A AN THE'
list_of_preps    = 'AT BY FOR FROM IN OF TO WITH'

big_words       = 0   ;   small_words  = 0
number_articles = 0   ;   number_preps = 0

do while lines('poetry.txt') > 0
  line_str = linein('poetry.txt')  /* read a line of poetry         */
  line_str = translate(line_str)   /* translate to upper-case       */
  line_str = translate(line_str,'      ','.,!:;"') /* remove punc.  */
  call lineout ,space(line_str)    /* display converted input line  */
                                 
  do j=1 to words(line_str)        /* do while a word to process    */
     if wordlength(line_str,j) >= 5 then
         big_words = big_words + 1             /* count big words   */
     else
         small_words = small_words + 1         /* count small words */
     word_to_analyze = word(line_str,j)        /* get the word      */
     if wordpos(word_to_analyze,list_of_articles) > 0 then
         number_articles = number_articles + 1 /* count the articles*/
     if wordpos(word_to_analyze,list_of_preps) > 0 then
         number_preps = number_preps + 1       /* count prep phrases*/
  end
end                
say
say 'Ratio long/short words: ' (big_words/small_words)
say 'Number of articles: ' number_articles
say 'Number of prepositions:' number_preps
say 'Ratio of preps/total words:' (number_preps/(big_words+small_words))

To get a feel for Rexx, let’s walk through the code.

The first two executable lines of the program define two lists:

list_of_articles = 'A AN THE'
list_of_preps    = 'AT BY FOR FROM IN OF TO WITH'

As subsequent code demonstrates, Rexx makes a good vehicle for list processing. Many programming problems can be defined and resolved through the “list processing paradigm.” Rexx also works well for string processing, records processing, and other paradigms (for example, the object paradigm in ooRexx). Rexx supports all the data structures used in the different processing paradigms.

The declarations of variables big_words, small_words, number_articles, and number_preps show that Rexx is a free format language:

big_words       = 0   ;   small_words  = 0
number_articles = 0   ;   number_preps = 0

These lines stack more than one statement per line by ending statements with semicolons. You don’t need to terminate Rexx statement otherwise. Nor does Rexx require much syntax. (Scan the program and you’ll see.) This syntactical simplicity is a big benefit. I code Rexx from memory, which I still can’t do after years of coding Korn and Perl.

Another aspect of its simplicity is that Rexx does not require declaring variables. (I declared big_words, small_words, number_articles, and number_preps in order to initialize these counters to 0.) But like any interpreter designed for large coding projects, Rexx offers a way to override this default behavior and require that all variables be pre-defined. Choices like this render an easy-to-use language powerful.

The do while statement shows off another of the many techniques through which Rexx mates simplicity and power:

do while lines('poetry.txt') > 0

The file poetry.txt does not need to be explicitly opened or closed. There are no statements that open or close this file in the program. Rexx follows this principle throughout – automate everything possible. This minimizes coding effort and maximizes simplicity and power. Yet one can always override these common-sense, default behaviors — an absolute requirement of any true “power language.” For example, Rexx provides the stream function if you need to open, process, and close a file in atypical fashion.

The several lines of code after the do while use the built-in Rexx functions linein, translate, and lineout to read an input line, translate it to upper-case and remove punctuation, and write it:

line_str = linein('poetry.txt')  /* read a line of poetry         */
line_str = translate(line_str)   /* translate to upper-case       */
line_str = translate(line_str,'      ','.,!:;"') /* remove punc.  */
call lineout ,space(line_str)    /* display converted input line  */

You can identify Rexx functions because all are followed immediately by a parentheses that contain arguments. A function without any arguments still requires parentheses, as in example().

Rexx has a very small, simple instruction set, surrounded by a large function library. Like C or C++, the result is that you can start programming with minimal knowledge, yet power is available as you learn the functions and classes.

The interior do loop uses the built-in functions words, wordlength, wordpos, and word to analyze each line of text:

 do j=1 to words(line_str)        /* do while a word to process    */
     if wordlength(line_str,j) >= 5 then
         big_words = big_words + 1             /* count big words   */
     else
         small_words = small_words + 1         /* count small words */
     word_to_analyze = word(line_str,j)        /* get the word      */
     if wordpos(word_to_analyze,list_of_articles) > 0 then
         number_articles = number_articles + 1 /* count the articles*/
     if wordpos(word_to_analyze,list_of_preps) > 0 then
         number_preps = number_preps + 1       /* count prep phrases*/
  end

This processing counts “big” and “small” words, the articles and the prepositions. words returns the number of words in a string, while word returns a specified word from the string. wordpos returns the word number position of a word in a string, and wordlength provides the length of a word.

All Rexx functions can be written one per line, as in the program code, or nested to any level. I’ve kept it simple here.

The concluding lines in the program use the say instruction to automatically concatenate and write out text strings or labels along with calculations:

say 'Ratio long/short words: ' (big_words/small_words)
say 'Number of articles: ' number_articles
say 'Number of prepositions:' number_preps
say 'Ratio of preps/total words:' (number_preps/(big_words+small_words))

As this program shows, Rexx is especially noted for its string processing power. Many problems can be solved through this paradigm and Rexx is quite adept at it.

While this poetry processing program is procedural, you can also use regular expressions to achieve the same result. Regular expressions are a succinct, non-procedural way to process strings (text). Grounded in pattern matching, they can reduce code and result in elegant text-processing solutions.

Rexx offers regular expressions through its external function libraries. Many of the thousands of free Rexx add-in tools are supplied in the form of such function libraries. You code and use the functions in these libraries just like Rexx’s own built-in functions (once you’ve coded a line or two to establish access to the external function library). With Rexx (as in Python), you have several different forms of regular expression processing available in different free external function packages.

This brief program gives you a feel for Rexx – its lack of syntax, its high level of automation, how it combines simplicity with power, and the way in which its flexibility solves problems with different processing paradigms.

I’ve left out objects. If readers are interested, I’ll follow up this article with another that will specifically look at Open Object Rexx. ooRexx, as it’s called, combines the simplicity and power of procedural Rexx with all the capabilities of object-oriented programming.


Learn More…

Rexx supports dozens of web sites in many spoken tongues. Start with these—

- RexxInfo Start here… downloads, interpreters, tools, tutorials, sample code, everything
- ooRexx.org The official home of Open Object Rexx… information, downloads, documentation
- Rexx Language Association The user group of the Rexx community


Howard Fosdick is the author of the The Rexx Programmer’s Reference, the complete 700-page tutorial and reference guide to all varities of Rexx, its interpreters and tools. He has coded in most major scripting and programming languages.